-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting to handle error response same as success #2564
Comments
Hey, you might want to look into the response-targets extension, which could suit your needs here |
@Telroshan Thanks for the link, I've actually already written my own version of I don't understand why the Hypermedia API reponse must be handled differently for error status codes? Maybe there is a way to do this? addEventListener("htmx:responseError", (e) => {
// Handle event same as success code
htmx.handle(e)
}) |
There was discussion to add a similar feature to the lib's core but it didn't make it through. However, please note htmx 2 will come with a |
The main page of the docs also has a section on Modifying swapping behavior with events where it’s recommended to use the (Myself, I’d still prefer to be able to declare any response should be handled directly in the triggering element with an attribute than writing a snippet of custom JS, though – but adding a simple even handler isn’t too bad) |
@silmeth Thanks for the tip, to display errors by default, I'm setting addEventListener("htmx:beforeSwap", (e) => {
if (e.detail.xhr.status >= 400) {
e.detail.shouldSwap = true
}
}) To override where the error is displayed, I can set |
When the response status is >= 400, the htmx:responseError event must be used, see this comment
Wouldn't it make sense to have a setting where htmx will still process the response as usual even for error responses?
For example, say I make a requests like this
And the response from the server, with status code 404, is this
I would like htmx to still process hx-swap-oob the same as status code 200
Also posted here
The text was updated successfully, but these errors were encountered: