Skip to content

Commit

Permalink
Improve network error detection across browsers (#152)
Browse files Browse the repository at this point in the history
* Improve network error detection across browsers

* extra semicolons removed

---------

Co-authored-by: Shulga, Ruslan X <[email protected]>
  • Loading branch information
nycruslan and Shulga, Ruslan X authored Oct 3, 2024
1 parent feb9589 commit 7f8e846
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ class Backend {
this.options.request(this.options, url, payload, (err, res) => {
if (res && ((res.status >= 500 && res.status < 600) || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true /* retry */)
if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false /* no retry */)
if (!res && err && err.message && (err.message.toLowerCase().indexOf('failed') > -1 && (err.message.indexOf('fetch') > -1 || err.message.toLowerCase().indexOf('network') > -1))) return callback('failed loading ' + url + ': ' + err.message, true /* retry */)
if (!res && err && err.message) {
const errorMessage = err.message.toLowerCase()
const isNetworkError = errorMessage.includes('failed') || errorMessage.includes('fetch') || errorMessage.includes('network') || errorMessage.includes('load')
if (isNetworkError) {
return callback('failed loading ' + url + ': ' + err.message, true /* retry */)
}
}
if (err) return callback(err, false)

let ret, parseErr
Expand Down

0 comments on commit 7f8e846

Please sign in to comment.