Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 502 an appropriate status code for a database error?

The definition of the 502 Bad Gateway status code is:

The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.

Is it an appropriate status code to respond with if the error was caused by the database? Despite the fact that the definition of the 500 Internal Server Error status code doesn't state that the error has to be internal, I don't like using it when the error is external.

Can the web server be considered to be a gateway or a proxy, since it is performing tasks other than communicating with the database, such as making calls to other APIs and services?

like image 302
akukas Avatar asked Mar 27 '16 02:03

akukas


People also ask

What is error code in database error?

Your web application communicating with a database server is outside the realm of HTTP and any errors should be wrapped in the generic HTTP 500 Internal server error response code.

What is the first digit of status codes that indicate a server error?

5xx server errors Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has encountered an error or is otherwise incapable of performing the request.

Why do we use 200 OK web server?

The HTTP 200 OK success status response code indicates that the request has succeeded. A 200 response is cacheable by default. The meaning of a success depends on the HTTP request method: GET : The resource has been fetched and is transmitted in the message body.

Which HTTP status code is usually returned when a resource is cached?

The HTTP 304 Not Modified client redirection response code indicates that there is no need to retransmit the requested resources. It is an implicit redirection to a cached resource.


2 Answers

No, I don't think an HTTP 502 Bad Gateway error is appropriate when a database error occurs.

HTTP errors say something about the HTTP protocol. This specific error indicates a server is trying to relay the HTTP request, but the upstream server did not respond correctly.

Your web application communicating with a database server is outside the realm of HTTP and any errors should be wrapped in the generic HTTP 500 Internal server error response code.

like image 69
MvdD Avatar answered Sep 21 '22 06:09

MvdD


There is no reference for the Database error status code. You can use 500 Internal Server Error as a response.

like image 30
Abid Avatar answered Sep 24 '22 06:09

Abid