14 """Reference implementation for status mapping in gRPC Python."""
16 from google.rpc
import status_pb2
19 from ._common
import GRPC_DETAILS_METADATA_KEY
20 from ._common
import code_to_grpc_status_code
24 """Returns a google.rpc.status.Status message from a given grpc.aio.Call.
26 This is an EXPERIMENTAL API.
29 call: An grpc.aio.Call instance.
32 A google.rpc.status.Status message representing the status of the RPC.
34 code = await call.code()
35 details = await call.details()
36 trailing_metadata = await call.trailing_metadata()
37 if trailing_metadata
is None:
39 for key, value
in trailing_metadata:
40 if key == GRPC_DETAILS_METADATA_KEY:
41 rich_status = status_pb2.Status.FromString(value)
42 if code.value[0] != rich_status.code:
44 'Code in Status proto (%s) doesn\'t match status code (%s)'
46 if details != rich_status.message:
48 'Message in Status proto (%s) doesn\'t match status details (%s)'
49 % (rich_status.message, details))