Skip to content

Commit

Permalink
Fix network issue (#944)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
HarelM authored Jan 21, 2025
1 parent a21efcc commit b429bb1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- _...Add new stuff here..._

### 🐞 Bug fixes

- Fix incorrect handing of network error response (#944)
- _...Add new stuff here..._

## 2.1.1
Expand Down
11 changes: 7 additions & 4 deletions src/libs/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down

0 comments on commit b429bb1

Please sign in to comment.