feat: reload the page with a flash when an htmx request fails

This commit is contained in:
fromme committed 2026-09-17 16:48:48 +02:00
1 parent 0be3c2ccde
commit a2e4035889
14 files changed
+205 -210

No files matched your search

+8
View File
@@ -23,3 +23,11 @@ htmx.config.responseHandling = [
{ code: '422', swap: true, error: false },
{ code: '[45]..', swap: false, error: true },
];
// Anything else that fails -- a 4xx other than 422, a 5xx, or no response at all -- reloads the
// page. htmx only opens modals and refreshes fragments, so there is always a whole page underneath,
// and every page is a GET: reloading is safe, closes the modal and shows current data. The server
// keeps honest status codes and leaves a flash explaining the reload (HtmxErrorFlashListener).
const reloadPage = () => window.location.reload();
document.addEventListener('htmx:responseError', reloadPage);
document.addEventListener('htmx:sendError', reloadPage);