Siddu H
Siddu H

Reputation: 11

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

Upvotes: 0

Views: 725

Answers (3)

cmlonder
cmlonder

Reputation: 2530

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.

Upvotes: 1

Axel Anaya
Axel Anaya

Reputation: 122

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

Upvotes: 0

Sriram Narayanan
Sriram Narayanan

Reputation: 103

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

Upvotes: 1

Related Questions