[openstreetmap/openstreetmap-website] Check response.ok before parsing JSON in query tool (PR #6724)

Tom Hughes notifications at github.com
Tue Jan 20 18:33:58 UTC 2026


@tomhughes requested changes on this pull request.

In addition to the specific inline requests can you please squash the second commit into the first one. 

> @@ -214,6 +214,7 @@ def stub_overpass(nearby_elements: [], enclosing_elements: [])
                 elements = data.includes("is_in") ? #{enclosing_elements.to_json} : #{nearby_elements.to_json};
 
           return Promise.resolve({
+            ok:true,

Space after the colon please, for consistency:

```suggestion
            ok: true,
```

> @@ -224,9 +238,7 @@ OSM.Query = function (map) {
       })
       .catch(function (error) {
         if (error.name === "AbortError") return;
-

Why are we getting rid of these blank lines?

> -      .then(response => response.json())
+      .then(async response => {
+        if (response.ok) {
+          return response.json();
+        }
+
+        const status = response.statusText || response.status;
+
+        if (response.status !== 400) {
+          throw new Error(status);
+        }
+
+        const text = await response.text();
+        throw new Error(text || status);
+      })
+

Get rid of this blank line please - it needs to be clear that there's another operation chained after this call.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6724#pullrequestreview-3683709344
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/6724/review/3683709344 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20260120/5311dd86/attachment-0001.htm>


More information about the rails-dev mailing list