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
Event Detail
ctx- Request context at time of errorerror- 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.