Is 502 an appropriate status code for a database error?
<p>The definition of the <code>502 Bad Gateway</code> status code is:</p>

<blockquote>
  <p>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.</p>
</blockquote>

<p>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 <code>500 Internal Server Error</code> status code doesn't state that the error has to be internal, I don't like using it when the error is external.</p>

<p>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?</p>