Skip to content

Instantly share code, notes, and snippets.

@keeth
Last active Feb 20, 2020
Embed
What would you like to do?
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