DevKits
502

Bad Gateway

5xx Server Error

Last updated:

The server, acting as a gateway or proxy, received an invalid response from the upstream server.

Description

The classic 'my origin server is broken' error from CDNs and load balancers. Common causes: upstream returned malformed HTTP, or the upstream process crashed mid-response.

When to use

Automatic on most proxies (nginx, Cloudflare, ALB) when upstream fails. You rarely emit 502 from application code.

Specification

RFC 9110 §15.6.3

Examples

HTTP response
HTTP/1.1 502 Bad Gateway
Content-Type: application/json

{"error":"Bad Gateway"}
Node.js (Express)
res.status(502).json({ error: "Bad Gateway" });
Go (net/http)
w.WriteHeader(http.StatusBadGateway)
Python (Flask)
return jsonify({"error": "Bad Gateway"}), 502

Related status codes

All 5xx codes