Exemplo n.º 1
0
def process(stub):
    try:
        response = stub.SayHello(helloworld_pb2.HelloRequest(name='Alice'))
        _LOGGER.info('Call success: %s', response.message)
    except grpc.RpcError as rpc_error:
        _LOGGER.error('Call failure: %s', rpc_error)
        status = rpc_status.from_call(rpc_error)
        for detail in status.details:
            if detail.Is(error_details_pb2.QuotaFailure.DESCRIPTOR):
                info = error_details_pb2.QuotaFailure()
                detail.Unpack(info)
                _LOGGER.error('Quota failure: %s', info)
            else:
                raise RuntimeError('Unexpected failure: %s' % detail)
Exemplo n.º 2
0
def create_greet_limit_exceed_error_status(name):
    detail = any_pb2.Any()
    detail.Pack(
        error_details_pb2.QuotaFailure(violations=[
            error_details_pb2.QuotaFailure.Violation(
                subject="name: %s" % name,
                description="Limit one greeting per person",
            )
        ],))
    return status_pb2.Status(
        code=code_pb2.RESOURCE_EXHAUSTED,
        message='Request limit exceeded.',
        details=[detail],
    )