Which http status code is suitable for when request data is correct and response data is not proper

I have situation where request syntax and data is proper and the data received from database is not in expected format – its a case of response data issue – In this scenario what is the suitable http status code.

Thought to use 422 – Unprocessable entity – its more on request body validation – please suggest

Thanks

3
Leave a Reply

avatar
3 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

4xx Client Error

The 4xx class of status code is intended for cases in which the client seems to have erred.

So, 4xx codes should be used only for client side errors, in your case, you should use an 5xx error, the best option in your situation is 500

The server encountered an unexpected condition which prevented it from fulfilling the request.

You can see more HTTP Status Codes here

Jason
Guest

Probably Internal Server Error(500) as the error is occurring on the server end.
4XX is only for client-side errors.

Jason
Guest

I like to think in this way;

  • Can the client(or user) get rid of the problem by himself, like changing request params or syntax? Use 4XX codes
  • Isn’t there anything he can do without contacting support service? Use 5XX codes

In your case I would still think about the scenario;

  • User is requesting with correct syntax
  • Data is proper

So why returned data is not in expected format? Then there is a problem while data is being written do DB like missing validations etc. or some bugs exist.