vanguard-go
vanguard-go copied to clipboard
Return 400 Bad Request to REST downstreams if the request is invalid
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
orgrpc: 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.