Add global HTMX error handler to prevent JS errors when error container is missing
This commit is contained in:
@@ -20,6 +20,11 @@ $(document).ready(function () {
|
||||
|
||||
document.body.addEventListener("htmx:responseError", function(e) {
|
||||
let el = document.getElementById("htmx-error");
|
||||
if (!el) {
|
||||
// No global error container available; log and return to avoid JS errors
|
||||
console.error('htmx:responseError but no #htmx-error element present', e.detail);
|
||||
return;
|
||||
}
|
||||
var error;
|
||||
if (e.detail.pathInfo.requestPath.includes("cimar") && e.detail.xhr.status == 403) {
|
||||
error = "Cimar permission error, please login and refresh the page.";
|
||||
|
||||
@@ -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 %}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user