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
+5
View File
@@ -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.";