-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby-source-graphql): Default Apollo Link fetch wrapper to sho…
…w better API errors (#28786) * apollo fetch http error status * update tests Co-authored-by: Vladimir Razuvaev <[email protected]> Co-authored-by: gatsbybot <[email protected]>
- Loading branch information
1 parent
3b40d80
commit abdb8d6
Showing
3 changed files
with
20 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const nodeFetch = require(`node-fetch`) | ||
|
||
// this is passed to the Apollo Link | ||
// https://www.apollographql.com/docs/link/links/http/#fetch-polyfill | ||
|
||
exports.fetchWrapper = async (uri, options) => { | ||
const response = await nodeFetch(uri, options) | ||
|
||
if (response.status >= 400) { | ||
throw new Error( | ||
`Source GraphQL API: HTTP error ${response.status} ${response.statusText}` | ||
) | ||
} | ||
|
||
return response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters