From 14391212bf45eff26afa3c321b765d6d1d4eb1f8 Mon Sep 17 00:00:00 2001 From: Harel M Date: Sun, 29 Sep 2024 13:08:49 +0000 Subject: [PATCH 1/3] Fix network issue --- src/libs/metadata.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libs/metadata.ts b/src/libs/metadata.ts index f724661f..bf2af9ad 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) }) } From 317448dc3f9307618d33a6760333be05195f9933 Mon Sep 17 00:00:00 2001 From: Harel M Date: Sun, 29 Sep 2024 13:13:37 +0000 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51bd16e6..2bed0666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - _...Add new stuff here..._ ### 🐞 Bug fixes + +- Fix incorrect handing of network error response (#944) - _...Add new stuff here..._ ## 2.1.1 From 28498d57f8829662ef19d9a820d36f17777bcdf4 Mon Sep 17 00:00:00 2001 From: Harel M Date: Mon, 30 Sep 2024 10:07:18 +0300 Subject: [PATCH 3/3] Apply suggestions from code review --- src/libs/metadata.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/metadata.ts b/src/libs/metadata.ts index bf2af9ad..dcc01243 100644 --- a/src/libs/metadata.ts +++ b/src/libs/metadata.ts @@ -11,10 +11,10 @@ function loadJSON(url: string, defaultValue: any, cb: (...args: any[]) => void) } return response.json(); }) - .then((body) =>{ + .then((body) => { cb(body) }) - .catch(() =>{ + .catch(() => { console.warn('Can not load metadata for ' + url + ', using default value ' + defaultValue); cb(defaultValue) })