0

I submit a form using ajax, and the validation is done on server side. If validation fails I return a json encoded object with the errors and status code: 500. When on client side jquery gets the response my error handler function is called and it works perfectly, BUT (probably this is a normal behavior) an exception is thrown in Chrome (probably other browser too):

POST http://localhost/workplace/.../clients/create 500 (Internal Server Error)

This makes me and probably my clients 'feel' that my program isn't working correctly, but there is just a validation error. How to handle this situation?

Tamás Pap
  • 17,777
  • 15
  • 70
  • 102

1 Answers1

1

You shouldn't return a 500 (Internal Server Error) Code. This is to indicate that is something wrong with the server (not with the request). This is probably what is causing the exception. I believe that is fine to return a 200 (OK) code. You don't need to reflect the validation error in the HTTP status code.

kgiannakakis
  • 103,016
  • 27
  • 158
  • 194