Fix upstream errors faster: use 502 when a gateway gets an invalid upstream response, and 504 when the upstream service exceeds your timeout budget.
Last reviewed: February 20, 2026|Editorial standard: source-backed comparison guidance
HTTP/1.1 502 Bad Gateway
Content-Type: application/json
{
"error": "bad_gateway",
"gateway": "edge-gateway-01",
"upstream": "payments-service",
"message": "Received invalid response from upstream."
}HTTP/1.1 504 Gateway Timeout
Content-Type: application/json
{
"error": "gateway_timeout",
"gateway": "edge-gateway-01",
"upstream": "payments-service",
"message": "Upstream did not respond before timeout budget expired."
}504 is defined for a server acting as a gateway/proxy. An origin can return 504 only when it is acting in that intermediary role for another upstream.
No. 504 means the intermediary timed out waiting for upstream. Client-side timeout events can happen separately and may not map to an HTTP response.
Not by default. The status code alone does not guarantee retry safety; decide by method idempotency, client policy, and observed failure mode.
Debug 500 vs 502 faster: use 500 for origin failures and 502 for invalid upstream responses at gateways, then route incidents to the right team.
Fix API payload issues faster by using 400 for malformed syntax and 422 for semantic validation failures, so clients correct format before business rules.