aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2025-05-27 22:46:00 +0200
committerGuilhem Moulin <guilhem@fripost.org>2025-05-27 22:46:14 +0200
commitee2e82b8405541b4a711050117bd58bfc82e2db5 (patch)
tree64de804d51c4748ab5110ac631045a06297d87cf
parent1e67d1de88b5dcafe56db2a28c26750daa50c5f8 (diff)
JS Fetch API: Don't try to decode JSON if the status code isn't 200.HEADmaster
-rw-r--r--main.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/main.js b/main.js
index 88ac044..231f492 100644
--- a/main.js
+++ b/main.js
@@ -3870,7 +3870,14 @@ const [vectorLayers, featureOverlayLayer] = (function() {
headers: {
'Content-Type': 'application/json; charset=UTF-8'
}
- }).then((resp) => resp.json())
+ })
+ .then(function(resp) {
+ if (resp.status === 200) {
+ return resp.json();
+ } else {
+ throw new Error(`${resp.url} [${resp.status}]`);
+ }
+ })
.then(function(data) {
/* the data is received from the CGI in the order it was sent */
/* TODO optimizations on the CGI would break the above assumption, so the
@@ -3916,6 +3923,9 @@ const [vectorLayers, featureOverlayLayer] = (function() {
popover.tip.classList.remove('inprogress');
}
})
+ .catch(function(e) {
+ console.log(e);
+ })
.finally(function() {
document.body.classList.remove('inprogress');
});