Is 502 an appropriate status code for a database error?

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.


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