From 2a88ab3f09a4b823fa8e52fe1fe12f7009d5ca0a Mon Sep 17 00:00:00 2001 From: Kyle Hensel Date: Mon, 29 Jun 2026 23:38:39 +1000 Subject: [PATCH] handle API errors with no content --- app/assets/javascripts/index/layers/data.js | 2 +- app/assets/javascripts/index_modules/new_note.js | 2 +- app/assets/javascripts/index_modules/note.js | 2 +- app/assets/javascripts/index_modules/query.js | 2 +- app/assets/javascripts/leaflet.map.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/index/layers/data.js b/app/assets/javascripts/index/layers/data.js index 712f299e7..937bf738a 100644 --- a/app/assets/javascripts/index/layers/data.js +++ b/app/assets/javascripts/index/layers/data.js @@ -113,7 +113,7 @@ OSM.initializeDataLayer = function (map) { return response.json(); } - const status = response.statusText || response.status; + const status = `HTTP Error ${response.status} ${response.statusText}`; if (response.status !== 400 && response.status !== 509) { throw new Error(status); } diff --git a/app/assets/javascripts/index_modules/new_note.js b/app/assets/javascripts/index_modules/new_note.js index b87435018..cbd52030e 100644 --- a/app/assets/javascripts/index_modules/new_note.js +++ b/app/assets/javascripts/index_modules/new_note.js @@ -21,7 +21,7 @@ export default function (map) { }) .then(resp => { if (resp.ok) return resp.json(); - throw new Error(`Got response with status ${resp.status} ${resp.statusText}`); + throw new Error(`HTTP Error ${resp.status} ${resp.statusText}`); }); } diff --git a/app/assets/javascripts/index_modules/note.js b/app/assets/javascripts/index_modules/note.js index 923fb5f45..122a74930 100644 --- a/app/assets/javascripts/index_modules/note.js +++ b/app/assets/javascripts/index_modules/note.js @@ -38,7 +38,7 @@ export default function (map) { .then(response => { if (response.ok) return response; return response.text().then(text => { - throw new Error(text); + throw new Error(text || `HTTP Error ${response.status} ${response.statusText}`); }); }) .then(() => { diff --git a/app/assets/javascripts/index_modules/query.js b/app/assets/javascripts/index_modules/query.js index b31ae3d61..94e3f4e5e 100644 --- a/app/assets/javascripts/index_modules/query.js +++ b/app/assets/javascripts/index_modules/query.js @@ -77,7 +77,7 @@ export default function (map) { if (response.ok) { return response.json(); } - throw new Error(response.statusText || response.status); + throw new Error(`HTTP Error ${response.status} ${response.statusText}`); }) .then(function (results) { let elements = results.elements; diff --git a/app/assets/javascripts/leaflet.map.js b/app/assets/javascripts/leaflet.map.js index 0c198960a..ba12d7fbb 100644 --- a/app/assets/javascripts/leaflet.map.js +++ b/app/assets/javascripts/leaflet.map.js @@ -304,7 +304,7 @@ L.OSM.Map = L.Map.extend({ throw new ElementGoneError(); } - const status = response.statusText || response.status; + const status = `HTTP Error ${response.status} ${response.statusText}`; if (response.status !== 400 && response.status !== 509) { throw new Error(status); } -- 2.47.3