Search code examples
parsinghttphttp-headershttp-error

What's the right HTTP error code if parsing the request fails


If you create a web service which receives an processes some data like XML/JSON and the parsing of the data fails because it's incorrect, what do you do?

  • Send a HTTP 400 error code: After all it was the client who messed up the data (XML/JSON)
  • Send a HTTP 500 error code: It's the server who wasn't able to complete its task

Solution

  • If data in the request is malformed, then you'll want to return a 400 level error. Generally 500-level errors mean that something is wrong on the server that has nothing to do with the client or the client's request.