14 """This example handles rich error status in client-side."""
16 from __future__
import print_function
20 from google.rpc
import error_details_pb2
22 from grpc_status
import rpc_status
24 from examples.protos
import helloworld_pb2
25 from examples.protos
import helloworld_pb2_grpc
27 _LOGGER = logging.getLogger(__name__)
33 _LOGGER.info(
'Call success: %s', response.message)
35 _LOGGER.error(
'Call failure: %s', rpc_error)
36 status = rpc_status.from_call(rpc_error)
37 for detail
in status.details:
38 if detail.Is(error_details_pb2.QuotaFailure.DESCRIPTOR):
39 info = error_details_pb2.QuotaFailure()
41 _LOGGER.error(
'Quota failure: %s', info)
43 raise RuntimeError(
'Unexpected failure: %s' % detail)
55 if __name__ ==
'__main__':