From: mmd-osm Date: Fri, 24 Jan 2025 22:02:22 +0000 (+0100) Subject: Added error handling for data layer X-Git-Tag: live~151^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/87e995bd84ec463f6d8915978c1aaeaedcc8b854?ds=sidebyside;hp=--cc Added error handling for data layer --- 87e995bd84ec463f6d8915978c1aaeaedcc8b854 diff --git a/app/assets/javascripts/index/layers/data.js b/app/assets/javascripts/index/layers/data.js index 0a996f0c7..7507a5f4e 100644 --- a/app/assets/javascripts/index/layers/data.js +++ b/app/assets/javascripts/index/layers/data.js @@ -63,6 +63,17 @@ OSM.initializeDataLayer = function (map) { .click(add))); } + function displayLoadError(message) { + $("#browse_status").html( + $("
").append( + $("

") + .text(I18n.t("browse.start_rjs.load_data")), + $("
").append( + $("
").append( + $("

") + .text(I18n.t("browse.start_rjs.feature_error", { message: message })))))); + } + var dataLoader; function getData() { @@ -114,6 +125,18 @@ OSM.initializeDataLayer = function (map) { } dataLoader = null; + }, + error: function (XMLHttpRequest, textStatus) { + dataLoader = null; + if (textStatus === "abort") { return; } + + if (XMLHttpRequest.status === 400 && XMLHttpRequest.responseText) { + displayLoadError(XMLHttpRequest.responseText); + } else if (XMLHttpRequest.statusText) { + displayLoadError(XMLHttpRequest.statusText); + } else { + displayLoadError(String(XMLHttpRequest.status)); + } } }); } diff --git a/config/locales/en.yml b/config/locales/en.yml index a7125a3a7..d528309f1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -392,6 +392,7 @@ en: relation: "relation" start_rjs: feature_warning: "Loading %{num_features} features, which may make your browser slow or unresponsive. Are you sure you want to display this data?" + feature_error: "Features could not be loaded: %{message}" load_data: "Load Data" loading: "Loading..." tag_details: