Search code examples
apihttphttp-status-codes

HTTP status code for noncritical server errors


Which HTTP status code shall I return, in my API, in case of non-critical server errors?

For example, SomeMethod is called, but fails, because of null passing, or maybe some errors while trying to access database, whatever.

I thought about 500 code, but it's used when server doesn't work at all, while SomeMethod works only if everything is correct.

Of course, body of response contains errors and their descriptions.


Solution

  • Since there's not a specific HTTP code for a "non-critical error", then all I can do is just tell you my opinion, which is - just use 200 and print an exception-like response.

    As you said in your comment - you are able to handle the internal error gracefully, so just throw an exception to the client that explains why his request failed (the "why" can be something like "internal database error").