Skip to content

502 Bad Gateway ​

Meaning ​

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.

When to Use ​

When a server is acting as a proxy or gateway (like an API gateway, reverse proxy, or load balancer) and the backend service returned an error or something invalid that prevents it from serving a proper response to the client.

Example ​

A reverse proxy tries to fetch data from an upstream service that crashes or returns malformed data; the proxy returns 502 Bad Gateway to the client because it got an invalid response from the upstream.

When Not to Use ​

Do not use if you are not acting as a proxy or gateway. For direct server errors, use 500 or appropriate code. Also, if the upstream response is valid but indicates an error (like a normal 500 from upstream), the gateway might just relay that code rather than turning it into 502.

Source ​

RFC 9110


Released under the MIT License.