Forwarding upstream connectrpc client errors results in incorrect content-type in server response
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:
- When the upstream service call throws (not catching, letting connectrpc forward it to frontend)
- connectrpc returns the error w/ content-type
application/grpc+protoinstead ofapplication/json - client in browser parses this as
ConnectError: [unknown] HTTP 500due 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
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?
Nice find. We'll confirm.