The server was acting as a gateway or proxy and received an invalid response from the upstream server.
What does HTTP 502 mean?
The 502 Bad Gateway code is part of the 5XX class. This is a server error code — the request was valid but the server failed to fulfil it. The problem is server-side.
When is it used?
A server returns 502 Bad Gateway in situations matching the definition above. You will encounter it inspecting network requests, reading logs, or testing an API. Whether it signals a problem depends on its class: 2xx and 3xx are normal, while 4xx and 5xx usually need attention on the client or server respectively.