0

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

2
  • 3
    4xx indicates a client error. You have a server error, so something in the 5xx range is appriorate. Either 500 (internal server error) or 503 (service unavailable) would be better. At least in my opinion. Commented Aug 2, 2019 at 5:35
  • It must be 500 as you met an error in server logic. Commented Aug 2, 2019 at 5:46

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

cmlonder,thanks -Its not really the data from our DB ,but from downstream system ,which we don’t have control on
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.