Requests get 502 Bad Gateway
A 502 from a project’s address means that what should have produced the answer failed. The body says which part it was. From the project’s own mocks:
Mock did not answer{ "type": "https://tools.ietf.org/html/rfc7807", "title": "Bad Gateway", "status": 502, "detail": "Mock response exceeded the plan traffic body limit."}From an upstream the project forwards to, the body is plain text, most often starting with one of these:
Upstream request failed: …Upstream unreachable: …Upstream response exceeded the … byte limit.Upstream refused: its address is not a public http or https address.Upstream connection failedRequest logs shows most of these requests with status 502, which tells you which cause you have: a forwarded request shows Forwarded to your upstream under Answered by, and Mock did not answer shows Mock server did not answer.
Causes
Section titled “Causes”The upstream failed
Section titled “The upstream failed”In Proxy unmatched mode the requests no mock matches, and in Record everything mode every request, are forwarded to the project’s Upstream base URL. When that fails, the caller gets 502 and a plain-text body naming the reason:
| Body | Cause |
|---|---|
Upstream request failed: no complete answer came back. |
The upstream refused the connection, broke it, or took more than 15 seconds in all |
Upstream request failed: it did not answer in time. |
The upstream sent nothing for 5 seconds |
Upstream unreachable: its host does not resolve. |
The upstream’s name does not resolve |
Upstream refused: its address is not a public http or https address. |
The name resolves to an address that is not public, such as one inside a private network, which MockHub never calls |
Upstream response exceeded the … byte limit. |
The upstream’s answer is larger than the plan’s traffic response body limit |
This destination is not allowed. |
A demo forwards only to MockHub’s sample API |
The body names neither the upstream nor the address it resolves to, because anyone can call the project’s address. The request log keeps the same body, so call the upstream yourself to see what it answers.
- Check the project’s Upstream base URL; Record traffic from a real API says where it is set.
- Call the upstream directly, with the same path, to see whether it answers, and how fast.
- For a slow or large endpoint, add a mock for it: in Proxy unmatched mode a matching mock answers before anything is forwarded.
An upstream that answers 502 itself is passed through unchanged, with its own body. See Gateway modes.
A chaos profile is live
Section titled “A chaos profile is live”A chaos profile’s connection faults, Connection reset by peer, Empty response, Malformed response chunk and Random data, then close, all reach the caller as 502, on the share of requests the profile sets. The body is Mock did not answer where a mock would have answered, and Upstream connection failed where the project would have forwarded the request.
The request log shows them under Mock server did not answer.
- Open the project’s Chaos tab. A live profile is listed first, marked Live.
- Select Stop on its row, or edit the profile to lower its fault rate.
To test a client against a response it can read, use the profile’s error injection with a status and body instead of a fault. See Create a chaos profile.
The mock’s response is too large
Section titled “The mock’s response is too large”Mock response exceeded the plan traffic body limit. means the mock’s rendered response is larger than the plan’s traffic response body limit. Such a request is not recorded in the request logs.
- Make the body smaller. A template that repeats a block, such as
{{#each (range 1 100000)}}, is the usual source. - For larger responses, the workspace Owner can move to a plan with a higher limit; the limits page lists them.
MockHub could not reach its mock server
Section titled “MockHub could not reach its mock server”Mock did not answer with no chaos profile live means the project’s mock server could not be reached, or did not answer within 70 seconds. The same trouble can also show as 503 with Service temporarily unavailable, or 500 with Failed to prepare the project's mocks. MockHub recovers from this on its own.
Retry after a moment. If it persists, report it.
The 502 is the project’s own answer
Section titled “The 502 is the project’s own answer”A mock whose status is 502, a response sequence step, or a chaos profile that injects 502 errors, answers with that status on purpose. Request logs then names the mock under Answered by. Open it from there and change what it answers.
Still stuck
Section titled “Still stuck”Report a problem with the time of the request, the project’s address and the full response body.