Skip to content
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

How to handle POST request errors? #41

Closed
bencroker opened this issue May 24, 2020 · 3 comments
Closed

How to handle POST request errors? #41

bencroker opened this issue May 24, 2020 · 3 comments

Comments

@bencroker
Copy link
Sponsor Collaborator

When using hx-post I see in the console a POST request to the value, quickly followed by a GET request to the value, the result of which is returned. Is it possible to handle errors that are returned in the POST response? All I see in the console is a 302 Found status and an empty body, even though my controller is returning a 200 with a body. Any insights into how this works would be much appreciated.

@rschroll
Copy link
Contributor

If your server is returning an error code, htmx will trigger the responseError event (https://htmx.org/events/#responseError.htmx). But it sounds like that isn't what's happening here.

You can turn on logging in htmx to see everything that's going on: https://htmx.org/docs/#events. It can be a little overwhelming, but maybe that will illuminate things more.

@1cg
Copy link
Contributor

1cg commented May 25, 2020

hey ben, can you post the HTML for me to look at? I don't know why a GET should be issued immediately after a POST, that sounds suspicious.

@bencroker
Copy link
Sponsor Collaborator Author

bencroker commented May 25, 2020

Thanks @rschroll and @chg20, after further investivation it seems the server was returning a 302 status after all. Fixing the controller to return a 200 status code solved it. The responseError event looks perfect for future use, cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants