diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fd7789a..8818fd2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - _...Add new stuff here..._ ### 🐞 Bug fixes + +- Fix incorrect handing of network error response (#944) - _...Add new stuff here..._ ## 2.1.1 diff --git a/src/libs/metadata.ts b/src/libs/metadata.ts index f724661f..dcc01243 100644 --- a/src/libs/metadata.ts +++ b/src/libs/metadata.ts @@ -5,14 +5,17 @@ function loadJSON(url: string, defaultValue: any, cb: (...args: any[]) => void) mode: 'cors', credentials: "same-origin" }) - .then(function(response) { + .then((response) => { + if (!response.ok) { + throw new Error('Failed to load metadata for ' + url); + } return response.json(); }) - .then(function(body) { + .then((body) => { cb(body) }) - .catch(function() { - console.warn('Can not metadata for ' + url) + .catch(() => { + console.warn('Can not load metadata for ' + url + ', using default value ' + defaultValue); cb(defaultValue) }) }