mmd-osm left a comment (openstreetmap/openstreetmap-website#6192)

Currently the export script returns errors as text/html, which Turbo happily 
picks up to replace the osm.org page. In this case, the user has to reload the 
page. Browser back button would take them to a random place, which is quite 
annoying.

Maybe it's better for the export script to return error messages as plain text. 
Turbo ignores this response, we can display the alert popup and nothing else 
happens.

As an alternative, 
https://discuss.hotwired.dev/t/finally-understanding-turbo-stream/1964/8 talks 
about some funny stuff we could do with Turbo Streams, though it seems a bit 
over-engineered for this use case.

leaflet.share.js:

```js
      } else {
        let detailMessage;
        try {
          detailMessage = event?.detail?.error?.message;
          if (!detailMessage) {
            detailMessage = await event.detail.fetchResponse.responseText;
          }
        } catch {
          detailMessage = "(unknown)";
        }
        // eslint-disable-next-line no-alert
        alert(OSM.i18n.t("javascripts.share.export_failed", { reason: 
detailMessage }));
      }
```
export.erb:

```python
# Routine to report an error
def output_error(message, status = "400 Bad Request"):
  print("Status: %s" % status)
  output_headers("text/plain")
  print(message)
```

Result:

<img width="414" height="138" alt="image" 
src="https://github.com/user-attachments/assets/1b4c99b3-3cdd-4c3a-a1f9-b62ef035595d";
 />


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

Message ID: 
<openstreetmap/openstreetmap-website/pull/6192/c3094256...@github.com>
_______________________________________________
rails-dev mailing list
rails-dev@openstreetmap.org
https://lists.openstreetmap.org/listinfo/rails-dev

Reply via email to