Fix network issue (#944)

## Launch Checklist

<!-- Thanks for the PR! Feel free to add or remove items from the
checklist. -->
In case of non 200 response the font and glyphs metadata would return
the ajax error object instead of the default value.

Fixes #935

- #935

 - [x] Briefly describe the changes in this PR.
 - [x] Link to related issues.
- [x] Include before/after visuals or gifs if this PR includes visual
changes.
 - [ ] Write tests for all new functionality.
 - [x] Add an entry to `CHANGELOG.md` under the `## main` section.
This commit is contained in:
Harel M
2025-01-21 16:25:03 +02:00
committed by GitHub
parent a21efcc4d5
commit b429bb16d7
2 changed files with 9 additions and 4 deletions
+2
View File
@@ -13,6 +13,8 @@
- _...Add new stuff here..._ - _...Add new stuff here..._
### 🐞 Bug fixes ### 🐞 Bug fixes
- Fix incorrect handing of network error response (#944)
- _...Add new stuff here..._ - _...Add new stuff here..._
## 2.1.1 ## 2.1.1
+7 -4
View File
@@ -5,14 +5,17 @@ function loadJSON(url: string, defaultValue: any, cb: (...args: any[]) => void)
mode: 'cors', mode: 'cors',
credentials: "same-origin" credentials: "same-origin"
}) })
.then(function(response) { .then((response) => {
if (!response.ok) {
throw new Error('Failed to load metadata for ' + url);
}
return response.json(); return response.json();
}) })
.then(function(body) { .then((body) => {
cb(body) cb(body)
}) })
.catch(function() { .catch(() => {
console.warn('Can not metadata for ' + url) console.warn('Can not load metadata for ' + url + ', using default value ' + defaultValue);
cb(defaultValue) cb(defaultValue)
}) })
} }