Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I return HTTP Status Code 500 (Internal Server Error) from REST application to client?

I have seen people using the HTTP code 500 as a generic error code for all kind of error cases (server errors, http errors, code exceptions, expected record not found in DB, time-out exceptions etc). However I have also read and heard that this code 500 should only be used in case of errors originating from the application server (JBoss in my case), and NOT application itself i.e. not for code-exceptions or invalid passwords or DB-record-not-found cases. So, when should we return HTTP Status Code 500 from a REST service method?

like image 363
Pratap Avatar asked Feb 23 '17 07:02

Pratap


People also ask

How does REST API handle 500 internal server error?

To be clear, if the error encountered by the server was due to CLIENT input, then this is clearly a CLIENT error and should be handled with a 4xx response code. The expectation is that the client will correct the error in their request and resubmit.

How do you fix 500 Internal server error There is a problem with the resource you are looking for and it Cannot be displayed?

500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed. To resolve this issue, set the Enable 32-bit Applications to "False": Open the Internet Information Services (IIS) Manager.

Is 500 error client side or server side?

The HTTP error code 500 ("internal server error") is reserved for serverside errors and you'll need to check the servers (error) logs for the cause, possibly after increasing the verbosity/debug level to get sufficient detail. Debugging from the client side alone will be nigh impossible.


1 Answers

As described in the HTTP spec:

The 5xx (Server Error) class of status code indicates that the server is aware that it has erred or is incapable of performing the requested method. Except when responding to a HEAD request, the server SHOULD send a representation containing an explanation of the error situation, and whether it is a temporary or permanent condition. A user agent SHOULD display any included representation to the user. These response codes are applicable to any request method.

Original: https://greenbytes.de/tech/webdav/rfc7231.html#rfc.section.6.6

Note that from the protocol point of view, it doesn't matter whether it's the application server or something running inside the application server.

like image 71
Julian Reschke Avatar answered Sep 23 '22 15:09

Julian Reschke