From ee2e82b8405541b4a711050117bd58bfc82e2db5 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Tue, 27 May 2025 22:46:00 +0200 Subject: JS Fetch API: Don't try to decode JSON if the status code isn't 200. --- main.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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'); }); -- cgit v1.2.3