foxts
Version:
Opinionated collection of common TypeScript utils by @SukkaW
1 lines • 1 kB
JavaScript
const e=Object.prototype.toString,t=new Set(["network error","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed","fetch failed","terminated"," A network error occurred.","Network connection lost"]),r=new Set(["ETIMEDOUT","ECONNRESET","ECONNREFUSED","ENOTFOUND","ENETDOWN","ENETUNREACH","EHOSTDOWN","EHOSTUNREACH","EPIPE","UND_ERR_SOCKET","UND_ERR_HEADERS_TIMEOUT"]);function o(o){if("object"!=typeof o||null==o)return!1;if("code"in o&&"string"==typeof o.code){if("ERR_UNESCAPED_CHARACTERS"===o.code)return!1;if(r.has(o.code))return!0}if(!(o&&"[object Error]"===e.call(o)&&"TypeError"===o.name&&"string"==typeof o.message))return!1;const{message:n,stack:E}=o;return"Load failed"===n||n.startsWith("Load failed (")&&n.endsWith(")")?void 0===E||"__sentry_captured__"in o:!!(n.startsWith("error sending request for url")||"Failed to fetch"===n||n.startsWith("Failed to fetch (")&&n.endsWith(")"))||t.has(n)}export{o as isNetworkError};