(no title)
mleonhard | 5 months ago
To handle errors in HTMX, I like to use config from [0] to swap responses into error dialogs and `hx-on-htmx-send-error` [1] and `hx-on-htmx-response-error` [2] to show the dialogs. For some components, I also use an `on-htmx-error` attribute handler:
// https://htmx.org/events/
document.body.addEventListener('htmx:error', function (event: any) {
const elt = event.detail.elt as HTMLElement
const handlerString = elt.getAttribute('on-htmx-error')
console.log('htmx:error evt.detail.elt.id=' + elt.getAttribute('id') + ' handler=' + handlerString)
if (handlerString) {
eval(handlerString)
}
});
This gives very good UX on network and server errors.[0]: https://htmx.org/quirks/#by-default-4xx-5xx-responses-do-not...
No comments yet.