Skip to content
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

graphQLErrors property passed to onError is sometimes an empty string #10590

Closed
6XGate opened this issue Feb 21, 2023 · 11 comments · Fixed by #11329
Closed

graphQLErrors property passed to onError is sometimes an empty string #10590

6XGate opened this issue Feb 21, 2023 · 11 comments · Fixed by #11329

Comments

@6XGate
Copy link

6XGate commented Feb 21, 2023

Issue Description

The type definitions for the onError link shows that graphQLErrors should always be an array of errors. Unfortunately when some servers return a 500 error, it will be an empty string.

Link to Reproduction

See repro steps

Currently I have to use the following code to prevent this from happening

onError(({ networkError }) => {
  if (networkError != null && 'result' in networkError && typeof networkError.result !== 'object') {
    networkError.result = { }
  }
})

Reproduction Steps

It is difficult to create a reproduction case with the given templates. Though I can if needed. But, the offending code is in at /src/link/error/index.ts:63 and may be a lack response parsing sanity checking or sanitation earlier on. It may also be that using a chaining of && should be replaced with something that ensures the networkError result is an object and not something else.

@jerelmiller jerelmiller added 🐞 bug 🏓 awaiting-team-response requires input from the apollo team labels Feb 21, 2023
@hichemBAALI
Copy link

hichemBAALI commented Mar 8, 2023

Any update here. I am still having the graphQLErrors: undefined when authLink fails (token expires). Please let me know if anyone faced the same issue

@6XGate
Copy link
Author

6XGate commented Mar 9, 2023

Any update here. I am still having the graphQLErrors: undefined when authLink fails (token expires). Please let me know if anyone faced the same issue

That would likely come in as networkError if the error is indicate via an HTTP status code like 401 or 403. AFAIK, getting those will results in an undefined graphQLErrors value. But, I filled this issue due to sometimes getting an empty string in those cases rather than undefined.

@jerelmiller
Copy link
Member

@6XGate this definitely seems like a bug, good catch! We should absolutely make sure that graphqlErrors never get set as an empty string in the event the server response is empty.

Would you be open to submitting a PR to get this fixed? I'd be more than happy to review it.

@6XGate
Copy link
Author

6XGate commented Mar 15, 2023

Can if I get a chance.

@bignimbus bignimbus removed the 🏓 awaiting-team-response requires input from the apollo team label Mar 16, 2023
@euc-callum
Copy link

We're also seeing this for 502 errors 👍

@fe-jcorreia
Copy link

This issue was fixed for new versions?

@jerelmiller
Copy link
Member

@fe-jcorreia nope this is still an issue. I'm just realizing though that we have #11329 open to address this. We'll see if we can get a review on that one soon. Thanks for the nudge.

@Tadimsky
Copy link

I just ran into this issue for our product, causing us to not handle the errors properly and silently fail.
It was for a 405 error response from our reverse proxy, we had just an empty string:
image

Is there a chance we can get this PR merged at some point? @jerelmiller

@jerelmiller
Copy link
Member

@Tadimsky gah thanks for the reminder. I've had a tab open to review it for a while and it kept slipping my mind. Just reviewed the PR that fixes this and will get it in the next patch release which should go out later this afternoon.

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants