connect-es icon indicating copy to clipboard operation
connect-es copied to clipboard

Forwarding upstream connectrpc client errors results in incorrect content-type in server response

Open sgtsquiggs opened this issue 3 months ago • 2 comments

Describe the bug

When an upstream grpc-go service is called (using connectrpc) within a connectrpc server implementation, and an error is returned, the content-type returned back to the browser is application/grpc+proto, which prevents the browser client from parsing the connectrpc error payload properly.

To Reproduce

Setup:

  • upstream go-grpc service
  • connectrpc nodejs service impl that calls upstream go-grpc service
    • served via express middleware

Bug:

  1. When the upstream service call throws (not catching, letting connectrpc forward it to frontend)
  2. connectrpc returns the error w/ content-type application/grpc+proto instead of application/json
  3. client in browser parses this as ConnectError: [unknown] HTTP 500 due to the content-type

If we create a new ConnectError, the content-type is properly set. The issue seems to be rooted around reusing the connect error.

Environment (please complete the following information):

  • @connectrpc/connect-web version: 2.1.0
  • @connectrpc/connect-node version: 2.1.0
  • Frontend framework and version: 18.3.1
  • Node.js version: 20.19.2
  • Browser and version: Chromium version 141.0.7390.123

sgtsquiggs avatar Oct 31 '25 17:10 sgtsquiggs

Thanks for the description. I think that the two statements line 275 to 278 should be swapped in handler-factory.ts. Can you confirm that this change fixes the issue?

timostamm avatar Oct 31 '25 18:10 timostamm

Nice find. We'll confirm.

sgtsquiggs avatar Oct 31 '25 18:10 sgtsquiggs