Add global HTMX error handler to prevent JS errors when error container is missing

This commit is contained in:
Ross
2026-03-02 10:39:46 +00:00
parent 166b0a0282
commit b3f5684e69
2 changed files with 19 additions and 0 deletions
+14
View File
@@ -219,6 +219,20 @@
});
</script>
<script>
// Page-level safe HTMX error handler: avoid throwing if global container missing
document.body.addEventListener('htmx:responseError', function (e) {
const el = document.getElementById('htmx-error');
if (!el) {
console.error('htmx response error (no #htmx-error):', e.detail);
return;
}
let error = e.detail && e.detail.xhr ? e.detail.xhr.response : 'Unknown error';
el.innerHTML = error;
el.classList.remove('hidden');
});
</script>
{% endblock %}