502是否是数据库错误的适当状态代码?

时间:2022-03-15 19:33:48

The definition of the 502 Bad Gateway status code is:

502 Bad Gateway状态代码的定义是:

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.

如果错误是由数据库引起的,它是一个适当的状态代码来响应吗?尽管500内部服务器错误状态代码的定义没有说明错误必须是内部的,但我不喜欢在错误是外部时使用它。

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?

Web服务器是否可以被视为网关或代理,因为它正在执行除与数据库通信之外的任务,例如调用其他API和服务?

1 个解决方案

#1


5  

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

不,我不认为发生数据库错误时HTTP 502 Bad Gateway错误是合适的。

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.

HTTP错误说明了HTTP协议。此特定错误表示服务器正在尝试中继HTTP请求,但上游服务器未正确响应。

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.

与数据库服务器通信的Web应用程序超出HTTP范围,任何错误都应包含在通用HTTP 500内部服务器错误响应代码中。

#1


5  

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

不,我不认为发生数据库错误时HTTP 502 Bad Gateway错误是合适的。

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.

HTTP错误说明了HTTP协议。此特定错误表示服务器正在尝试中继HTTP请求,但上游服务器未正确响应。

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.

与数据库服务器通信的Web应用程序超出HTTP范围,任何错误都应包含在通用HTTP 500内部服务器错误响应代码中。