Return 500 when an error is encountered

API User : Hi there. Long time no see.

API builder : Yes I was busy. The API code is in production now.

API User : I noticed. I got error message that something went wrong.

API builder : yes. I’m working on it.

API User : If something goes wrong then you should send response code 500.

API User : It means that something unexpected happened. Like an exception was raised or database could not be connected.

API User : Even in the case of 500 system should take utmost care that returned value is valid JSON or xml. Otherwise the client might run into problem while parsing the response body.