A pay-per-call endpoint has two failure directions, and they must not share a counter. When the caller sends something wrong, the answer is a refusal โ no money moves, nothing is broken. When the endpoint's own upstream is rate-limiting or down, the answer is a platform fault โ the buyer got nothing, but the service is not defective. Collapse both into one counter and the third time a free public API decides your shared egress IP is a bot, your paid listing is switched off.
That is not a hypothetical. On 2026-11-15 one paid call to one of our endpoints returned fetch failed โ our own upstream refusing us โ and the gateway booked it as a service failure, one of three that would have delisted a working service with no automatic recovery. The handler had done nothing wrong; it just reported the upstream's failure in a shape the gateway could not attribute.
Our gateway's delivery recorder reads one field out of the handler's answer: cause. outcome = failed with cause = "service" increments the failure counter; three increments and active = 0. There is an escape hatch โ cause = "platform" โ that books the failure without counting it against the service.
Two properties of that mechanism matter more than the mechanism:
cause to read. A 502 that says {"cause":"platform"} in its body is, to the counter, indistinguishable from a blank one.retryable: true is advisory. It is useful to the caller and it is ignored by the counter. A body that says "retryable: true" and omits cause still books a strike.So the fix is not a policy change inside the gateway. It is making every upstream-failure branch say, in the one field the recorder reads, whose fault it was โ in a shape that survives to the recorder.
We wrote a static census over the deployed handler tree: find every branch that reacts to an upstream non-2xx and classify whether the answer carries an attributable cause. 257 branches across 233 files. They fell into three shapes, and each needs a different fix.
| shape | why the counter sees nothing | fix |
|---|---|---|
throw new Error('HTTP ' + r.status) | the sidecar turns an unhandled throw into a 500 โ body unreadable | mark the error (e.upstreamStatus = r.status) and map marked 429/5xx throws centrally to a 200 body with cause:'platform' |
return { ok:false, error:'... HTTP ' + r.status } | the body arrives, but there is no cause key | add it conditionally: ...(r.status === 429 || r.status >= 500 ? { cause:'platform' } : {}) |
res.status(502).json({ error:'... HTTP ' + r.status }) | status โฅ 400, so the body is never delivered to the recorder | answer 200 + ok:false + cause:'platform' for 429/5xx only; keep the 502 for every other status |
The third row is the one that looks correct and is not. It is the natural way to write an express-style proxy: upstream failed, so I return a bad-gateway. The status is honest to a human reader and invisible to a machine that reads only successful responses. Changing it means an upstream outage now answers 200 {"ok":false,"cause":"platform"} โ a change in transport status, but not in meaning, because ok is already how callers tell success from failure.
The tempting version of this fix is to mark every non-2xx from upstream as a platform fault. That hides real defects. A 404 from a contract explorer, a 422 from a currency API, a 400 from a query the handler built badly โ those can all be the service's own fault, and they should keep counting. Our rule:
404 no orderbook for a resolved market, and one perp endpoint returns 500 for a ticker that is not listed. Those branches answer ok:true with an explanation, unchanged โ they are results, not failures.Internal calls got the unconditional version: a handler that fetches 127.0.0.1/api/stats and gets nothing back has no third party to blame.
Two batches today, 46 branches in 44 files. The census counts "strike-risk" branches โ those that can turn an upstream failure into a service strike:
| measure | before | after |
|---|---|---|
| branches with an unattributable upstream failure | 240 | 195 |
| branches in the "thrown, no marker" shape | 38 | 0 |
| branches in the "returned ok:false, no cause" shape | 37 | 0 |
| express 502-on-upstream-failure sites | 3 | 0 for 429/5xx |
What remains is not the same problem. 143 branches already answer 429/5xx with cause:'platform' and still book a strike on other statuses โ intended. 13 are shapes our census cannot classify, and every one of them answers ok:true with an unassessed flag: a delivered answer, not a failure. The counter does not see them.
Stub the upstream, not the network. For each changed handler, replace fetch with a function that answers a fixed status, then assert three cases: 503 carries cause:'platform', 400 does not, and any "upstream said no" branch still answers ok:true.
global.fetch = async () => ({ ok: false, status: 503, json: async () => ({}) });
await handler({ from: 'USD', to: 'EUR' }, {}, {});
// โ { ok: false, cause: 'platform', upstreamStatus: 503, error: 'rate fetch HTTP 503' }
global.fetch = async () => ({ ok: false, status: 400, json: async () => ({}) });
// โ { ok: false, error: 'rate fetch HTTP 400' } โ still countable, by design
global.fetch = async () => ({ ok: false, status: 404,
json: async () => ({ error: 'No orderbook exists for the requested token id' }) });
// โ { ok: true, result: { noBook: true, ... } } โ an answer, not a failure
Then check that the running process loaded the bytes you tested: after a restart our sidecar logs loaded 1717 handlers (0 failed), and a freshness check confirms every handler file predates the load. A fix that is on disk and not in the running process is not a fix.
If a seller's endpoint disappears right after you retried it three times during their upstream's bad hour, the retries may be the reason. retryable: true in an error body describes what you should do, not what the bookkeeper did. Sellers who have not made this distinction are one rate-limit away from switching off a service that works.
And if you are the seller: the field your counter reads is the only field that matters. Not the HTTP status you thought was honest, not the retryable flag you took care to add. Write the cause, in a body the counter can read, or your upstream's bad day becomes your delisting.