]> git.openstreetmap.org Git - rails.git/commitdiff
Added error handling for data layer
authormmd-osm <mmd.osm@gmail.com>
Fri, 24 Jan 2025 22:02:22 +0000 (23:02 +0100)
committermmd-osm <mmd.osm@gmail.com>
Fri, 24 Jan 2025 22:14:08 +0000 (23:14 +0100)
app/assets/javascripts/index/layers/data.js
config/locales/en.yml

index 0a996f0c70c27244e7769f765f4586b425a9879c..7507a5f4e791875738f4c89023d73bcdd78133db 100644 (file)
@@ -63,6 +63,17 @@ OSM.initializeDataLayer = function (map) {
           .click(add)));
   }
 
           .click(add)));
   }
 
+  function displayLoadError(message) {
+    $("#browse_status").html(
+      $("<div class='p-3'>").append(
+        $("<h2 class='flex-grow-1 text-break'>")
+          .text(I18n.t("browse.start_rjs.load_data")),
+        $("<div>").append(
+          $("<div class='d-flex'>").append(
+            $("<p class='alert alert-warning'>")
+              .text(I18n.t("browse.start_rjs.feature_error", { message: message }))))));
+  }
+
   var dataLoader;
 
   function getData() {
   var dataLoader;
 
   function getData() {
@@ -114,6 +125,18 @@ OSM.initializeDataLayer = function (map) {
         }
 
         dataLoader = null;
         }
 
         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));
+        }
       }
     });
   }
       }
     });
   }
index a7125a3a7d5c8602597b14d29604bdf2fba3ec01..d528309f1bea521d221b869427908c00ca83d9c0 100644 (file)
@@ -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?"
         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:
       load_data: "Load Data"
       loading: "Loading..."
     tag_details: