8 ms·
How does one handle errors with MESH? To handle errors in HTMX, I like to use config from [0] to swap responses into error dialogs and `hx-on-htmx-send-error`
by mleonhard 1y ago
How does one handle errors with MESH?
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-swap https://htmx.org/quirks/#by-default-4xx-5xx-responses-do-not...
[1]: https://htmx.org/events/#htmx:sendError https://htmx.org/events/#htmx:sendError
[2]: https://htmx.org/events/#htmx:responseError https://htmx.org/events/#htmx:responseError