Skip to content

Instantly share code, notes, and snippets.

@keeth
Last active February 20, 2020 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keeth/d5d94dab40b4d697618c075e155197da to your computer and use it in GitHub Desktop.
Save keeth/d5d94dab40b4d697618c075e155197da to your computer and use it in GitHub Desktop.
Is it a fetch network error? (for the purpose of retrying on failure).
/*
https://twitter.com/xinganwang/status/1189266788237885443
github/fetch: TypeError: Network request failed
Chrome: TypeError: Failed to fetch
Firefox: TypeError: NetworkError when attempting to fetch resource.
Safari: TypeError: The Internet connection appears to be offline.
*/
const isNetworkError = e =>
/The Internet connection appears to be offline|Failed to fetch|Network request failed|NetworkError when attempting to fetch resource|The network connection was lost/.test(
e.message
) ||
e.statusCode === 502 ||
e.statusCode === 504;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment