4

My web-application makes HTTP requests to an Extensible Service Proxy (ESP), which in-turn, delegates to a gRPC server (written in Python). Ignoring Android and iOS clients, the architecture is:

enter image description here

The ESP is a nginx reverse proxy.

The gRPC server ("Your code" in the reference architecture) may raise an exception, in which case I use context.abort to raise an exception and terminate the RPC with a non-OK status:

try:
  # Do something that could fail.
except ValueError as e:
  context.abort(grpc.StatusCode.DATA_LOSS, str(e))

While it is possible to use set_code and set_details, they still result in a HTTP status of 200 OK.

There are two problems:

  1. The gRPC status codes are translated by the ESP container (nginx proxy) to a a generic 500 Internal Server Error.

  2. The accompanying details are stripped-out.

  3. and 2. combined means the web client has, at most, a 500 Internal Server Error for all exceptions raised by the gRPC server.

Ultimately, I don't understand how more informative (ideally, custom) errors can be returned to web-clients.

Jack
  • 10,313
  • 15
  • 75
  • 118

1 Answers1

5

grpc Status code::DATA_LOSS, are translated to HTTP code 500. The code is here

The grpc status detail (status code and error message) are send back in the response body in JSON format. The code is here