grpc / grpc-go

The Go language implementation of gRPC. HTTP/2 based RPC
https://grpc.io
Apache License 2.0
20.84k stars 4.33k forks source link

Surface response body when receiving an unexpected status code and content-type #7406

Open drigz opened 1 month ago

drigz commented 1 month ago

Use case(s) - what problem will this feature solve?

When using a gRPC server through a reverse proxy, the client will sometimes see plaintext or HTML error served by the proxy. Currently, the user of the gRPC client just sees:

rpc error: code = Unknown desc = unexpected HTTP status code received from server: 500 (Internal Server Error); transport: received unexpected content-type "text/html"

Proposed Solution

It would be more helpful if the response body was included in the error, for example:

rpc error: code = Unknown desc = unexpected HTTP status code received from server: 500 (Internal Server Error); transport: received unexpected content-type "text/html"; response body:
<first N bytes of the response body if printable>

Alternatives Considered

This could also be added to the status details, so that they can be shown like this: https://jbrandhorst.com/post/grpc-errors/#:~:text=In%20order%20to%20extract%20these%20errors%20on%20the%20other%20side

Although of course this requires some more code on the client side, maybe not all users want to see the response body, as especially nginx can serve massive amounts of boilerplate HTML in its errors.

Additional Context

https://github.com/grpc/grpc-go/issues/1924#issuecomment-469870310 commented:

Still not returning the raw HTML, however, but I think we should cover that with a separate feature request instead of as part of this bug.

But I can't find that the FR was ever filed.

purnesh42H commented 1 month ago

@drigz I will discuss with team and get back to you

purnesh42H commented 1 month ago

@drigz as per discussion with team we currently don't have bandwidth to work on this with priority. We will keep this issue open and pick up later sometime.