Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Oct 3, 2024
1 parent 7f8e846 commit 18fac10
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 2.6.2

- improve network error detection across browsers [152](https://github.com/i18next/i18next-http-backend/pull/152)

### 2.6.1

- optimize "Failed to fetch" retry case [147](https://github.com/i18next/i18next-http-backend/issues/147)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![Actions](https://github.com/i18next/i18next-http-backend/workflows/node/badge.svg)](https://github.com/i18next/i18next-http-backend/actions?query=workflow%3Anode)
[![Actions deno](https://github.com/i18next/i18next-http-backend/workflows/deno/badge.svg)](https://github.com/i18next/i18next-http-backend/actions?query=workflow%3Adeno)
[![Travis](https://img.shields.io/travis/i18next/i18next-http-backend/master.svg?style=flat-square)](https://travis-ci.org/i18next/i18next-http-backend)
[![npm version](https://img.shields.io/npm/v/i18next-http-backend.svg?style=flat-square)](https://www.npmjs.com/package/i18next-http-backend)

This is a simple i18next backend to be used in Node.js, in the browser and for Deno. It will load resources from a backend server using the XMLHttpRequest or the fetch API.
Expand Down
10 changes: 9 additions & 1 deletion i18nextHttpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,15 @@ var Backend = function () {
this.options.request(this.options, url, payload, function (err, res) {
if (res && (res.status >= 500 && res.status < 600 || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true);
if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false);
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);
if (!res && err && err.message) {
var errorMessage = err.message.toLowerCase();
var isNetworkError = ['failed', 'fetch', 'network', 'load'].find(function (term) {
return errorMessage.indexOf(term) > -1;
});
if (isNetworkError) {
return callback('failed loading ' + url + ': ' + err.message, true);
}
}
if (err) return callback(err, false);
var ret, parseErr;
try {
Expand Down
2 changes: 1 addition & 1 deletion i18nextHttpBackend.min.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ class Backend {
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) {
const errorMessage = err.message.toLowerCase()
const isNetworkError = errorMessage.includes('failed') || errorMessage.includes('fetch') || errorMessage.includes('network') || errorMessage.includes('load')
// for example:
// Chrome: "Failed to fetch"
// Firefox: "NetworkError when attempting to fetch resource."
// Safari: "Load failed"
const isNetworkError = [
'failed',
'fetch',
'network',
'load'
].find((term) => errorMessage.indexOf(term) > -1)
if (isNetworkError) {
return callback('failed loading ' + url + ': ' + err.message, true /* retry */)
}
Expand Down

0 comments on commit 18fac10

Please sign in to comment.