-
-
Notifications
You must be signed in to change notification settings - Fork 454
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
Body parsing error for non-JSON 401 response #2442
Comments
I'm not quite exactly sure what you're patching without a reproduction, sorry 😅 As far as I recall this, the test is simply to check for multipart responses and that's simpler this way since the However, both eventually end up here: https://github.com/FormidableLabs/urql/blob/1ab77b65ef6ed0e85fb50a61b374b306ef046cf4/packages/core/src/internal/fetchSource.ts#L156 So I'm a little confused as to what difference this would make 🤔 |
Hmm, we might not in case we hit the if (!/multipart\/mixed/i.test(n)) {
return t.text().then(text => {
hasResults = true;
try {
const n = JSON.parse(text)
e(makeResult(r, n, t));
} catch (e) {
throw e;
}
})
} |
The problem is that this part of code assumes that the response is always a JSON string, in case the content type is different than // v--- this throws
return t.json() To be specific, my server (and a common pattern to do so) returns This is what my server's auth handling structure looks like: https://gqlgen.com/recipes/authentication/ Is this understandable? I may whip up a reproduction, though I will need a custom server for it, and thought the issue's simple enough to understand for that effort. |
This would still throw in case of a non-JSON response, wouldn't it? |
I mean, we could also just use Feel free to try the build at #2444 |
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
@urql/[email protected]
for the project I'm working on.I have a middleware on my server that returns a status
401
with a plain text ofinput: unauthorized request
for requests whose auth token verification fails (e.g. for a timeout). However, I am getting an error from this function, because it expects the response to be a JSON.I noticed the function's implementation checks for header type to determine the response handling, however, it'd be IMO better to explicitly check for
application/json
, rather that checking for notmultipart/mixed
.Here is the diff that solved my problem:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: