-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby-source-graphql): Default Apollo Link fetch wrapper to show better API errors #28786
Conversation
Thanks for the PR! Looks like a test needs updated https://app.circleci.com/pipelines/github/gatsbyjs/gatsby/55837/workflows/c9813a24-52f9-4308-b7c2-1779939215dc/jobs/589688 |
I've updated those failing tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvement, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Wow great, that was fast, thanks! |
…w better API errors (gatsbyjs#28786) * apollo fetch http error status * update tests Co-authored-by: Vladimir Razuvaev <[email protected]> Co-authored-by: gatsbybot <[email protected]>
Description
When the source GraphQL API responds with an error (4xx/5xx), the default behavior is to try to read the response body anyway, which is, in case of errors, often unrelated JSON, or HTML, or empty.
In these cases, we throw an error showing the HTTP response code and status text, which is much more relevant.
The user is still free to override the default
fetch
wrapper anyway.Documentation
https://www.gatsbyjs.com/plugins/gatsby-source-graphql/#how-to-use
https://www.apollographql.com/docs/link/links/http/#fetch-polyfill
Related Issues
#10487
#20892
#28766
Notes
We could add more logging by passing the
reporter
to the wrapper and add somereporter.verbose(...)
for stuff like the response body or the request body, but it might be better to leave that to the user since they can write their own fetch wrapper anyway.