Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I respond with a 400 error if a form submit contains validation errors?

In a classic form-based webapp, if a user submits a HTML form that contains validation errors, assuming no JavaScript, what's the correct thing to do?

  1. Respond with the HTTP 200 + the page content (including error info for the user)
  2. Respond with the HTTP 400 + the page content (including error info for the user)

Does it matter?

like image 623
Joe Avatar asked Oct 16 '25 18:10

Joe


1 Answers

Your app is talking to human beings, not other machines. Therefore you should do the right thing and handle exceptions in a user-friendly manner.

Your user doesn't care about HTTP return codes, and so it should not even be a consideration for you either. You are confusing business-logic problems with HTTP protocol problems.

Infact, by throwing a 400 error at a web-browser, you are only likely to encounter the web browser throwing up an ugly message to the user.

If you were coding a REST api, then the answer would be different. But you're not.

like image 63
Little Code Avatar answered Oct 18 '25 12:10

Little Code



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!