-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Way to recover from errors caused by non-compliant response body #469
Comments
Thank you for the request, Itaru. The response probably looks like this?
So there is:
And you see a ConnectError with Code.Internal and a message starting with "cannot decode ConnectError...", correct? |
@timostamm Exactly! Initially, the proxy returned "empty" body, and it caused I made a change to the proxy so that it returns |
Thank you for confirming. I agree that it would be very convenient to raise an error code matching the HTTP status here. On the other hand, this will shadow malformed responses. For example, consider this response:
It would be odd to see a ConnectError with code Unauthenticated raised, but never see the error message provided from the server. We are adding a "cause" property to ConnectError: I think this might help us to surface this condition. In the mean time, returning just the HTTP status - without a Content-Type - would be the most simple way to get unblocked:
|
Thank you for the advice. As I don't have control over the proxy behavior, I ended up with monkey-patching fetch function. const originalFetch = fetch;
window.fetch = async function(input: RequestInfo, init?: RequestInit) {
const reqHeaders = new Headers(init?.headers)
const connectVer = reqHeaders.get('Connect-Protocol-Version') ?? '';
const isConnect = parseInt(connectVer) > 0;
const res = await originalFetch(input, init);
if (isConnect && res.status === 401 && res.headers.get('Content-Type') === 'application/json') {
res.headers.set('Content-Type', '');
}
return res;
}
This sounds great. This way, you can access the underlying http response error? I'd definitely replace the monkey-patching with this approach once it's released! |
@itareeee, we ran into this very problem with Fastify 😄 This is fixed in #479. We are simply raising a |
This fix seems to perfectly solves my issue. Thank you so much! |
Is your feature request related to a problem? Please describe.
When connect-web client receives non-200 response with non-compliant response body, then it raises an error of Internal or Unknown though I'd rather have the error code corresponding to the http status code.
In my setup, there's an authentication proxy in front of connect-web server, and it returns http 401 response with empty body when failing to authenticate a request.
I suppose, it's common to have various reverse proxies, and they are usually not compatible with connect protocol.
Describe the solution you'd like
An option to enable fallback process that determines error type based on http status code in case of failing to parse response body.
Just like how error type is determined when content-type is not application/json.
https://github.com/bufbuild/connect-es/blob/d6598c5f9fe67f9165e3d06f84cf1a4c8d81f989/packages/connect-web/src/connect-transport.ts#L256-L259
The text was updated successfully, but these errors were encountered: