10 lines
449 B
JavaScript
10 lines
449 B
JavaScript
// By default htmx only swaps 2xx/304 responses into hx-target; 4xx/5xx
|
|
// responses are treated as errors and left unswapped. Our API handlers
|
|
// return error status codes with a plain-text body meant for the
|
|
// error-container div, so force the swap to happen anyway.
|
|
document.body.addEventListener("htmx:beforeSwap", function (evt) {
|
|
if (evt.detail.xhr.status >= 400) {
|
|
evt.detail.shouldSwap = true;
|
|
evt.detail.isError = false;
|
|
}
|
|
});
|