vanguard-go icon indicating copy to clipboard operation
vanguard-go copied to clipboard

Return 400 Bad Request to REST downstreams if the request is invalid

Open hperl opened this issue 5 months ago • 1 comments

When transcoding REST to a gRPC upstream, by default, all bad requests return a 500 instead a 400. The final error and status code can be rewritten in an HTTP middleware, but the error messages do not share a common prefix, so that I need to pattern-match all possible errors. For example:

  • passing a body to an endpoint that does not expect a body (no body set in the google.api.http option) returns: request should have no body; instead got %d bytes

  • passing invalid JSON to an endpoint that expects a body returns either proto: unexpected EOF or grpc: error unmarshalling request: proto: unexpected EOF , depending on the HTTP method (I think)

There might be other cases that I missed. Ideally, these error messages would all share a common prefix (i.e. vanguard: invalid request) so that some middleware can catch them and return a 400 ; or Vanguard would return a 400 to downstream for all decoding errors of the request by default.

hperl avatar Sep 20 '24 07:09 hperl