Skip to content

Commit

Permalink
* xover.fetch.json - added try/catch method
Browse files Browse the repository at this point in the history
  • Loading branch information
uriel-online committed Aug 28, 2024
1 parent 8b6edd0 commit 8dbeaff
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions xo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9541,8 +9541,17 @@ xover.fetch.json = async function (url, settings) {
url = new xover.URL(url);
}
url.settings["headers"].append("Accept", "application/json");
try {
let return_value = await xover.fetch.call(this, url, settings).then(response => response.json || response.body && Promise.reject(response));
return return_value;
} catch (e) {
if (e instanceof Response && e.ok) {
console.error(`response is not a valid json`, e.body);
return Promise.reject(new Error(`response is not a valid json`, e.url.href))
} else {
return Promise.reject(e)
}
}
}

xover.xml.fromString = function (xmlString) {
Expand Down

0 comments on commit 8dbeaff

Please sign in to comment.