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.
Last reviewed: February 20, 2026|Editorial standard: source-backed comparison guidance
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
{
"error": "internal_server_error",
"request_id": "req_7f8a12",
"message": "Unexpected exception while processing request."
}HTTP/1.1 502 Bad Gateway
Content-Type: application/json
{
"error": "bad_gateway",
"upstream": "orders-service",
"gateway": "edge-proxy-03",
"message": "Gateway received an invalid upstream response."
}Start with the gateway/platform boundary because 502 means an intermediary could not use upstream response correctly. Then involve upstream owners with correlated traces.
Only when that service is itself acting as a gateway/proxy for another upstream. Otherwise origin execution failures should generally surface as 500.
Yes. Direct origin calls can show 500 while gateway-mediated paths show 502 if intermediary-upstream contracts also fail under stress.
Fix upstream errors faster: use 502 when a gateway gets an invalid upstream response, and 504 when the upstream service exceeds your timeout budget.
Fix API payload issues faster by using 400 for malformed syntax and 422 for semantic validation failures, so clients correct format before business rules.