fullstorydev / grpchan

Channels for gRPC: custom transports
MIT License
204 stars 23 forks source link

add ability to customize HTTP error response for unary RPCs #46

Closed jhump closed 3 years ago

jhump commented 3 years ago

The provides a way for calling code to set a custom error renderer, to override the default mapping of gRPC errors to HTTP responses.

Since streams write the gRPC status into the body, as a trailing message, this is only for unary RPCs.

It also tweaks the existing mapping so that a Cancelled or DeadlineExceeded code only maps to 499 when the request context is cancelled. Otherwise, a 502 Bad Gateway or 504 Gateway Timeout status is used, respectively.

jhump commented 3 years ago

@dragonsinth, I pushed another commit because I realized that we should treat "Cancelled" similarly to "DeadlineExceeded".

dragonsinth commented 3 years ago

Not as certain about Cancelled.. I can see an argument for always 499'ing that.

jhump commented 3 years ago

Not as certain about Cancelled.. I can see an argument for always 499'ing that.

If the client has not actually cancelled, I don't think 499 is ever appropriate. That code is really for internal book-keeping as opposed to a code that we send to the client. (The client shouldn't ever be able to see one, since it means "client has closed the request".)