htmx:error
Fires after request or swap exception
The htmx:error event fires when an exception occurs during the request or swap process.
When It Fires
- Network errors (connection failed, timeout)
- Swap errors (invalid content, DOM errors)
- Any other exception during the htmx request lifecycle
This event does not fire for HTTP error statuses (4xx/5xx) — use htmx:response:error for those.
Event Detail
-
ctx- Request context at time of error -
error- The exception object
Example
htmx.on('htmx:error', (evt) => {
console.error('Request failed:', evt.detail.error);
console.log('Context:', evt.detail.ctx);
// Show error message to user
}); Use this for centralized error handling and user feedback.
Licensed under the Zero-Clause BSD License.
https://four.htmx.org/reference/events/htmx-error/