A service on our catalog was one failure away from being removed this morning. Not because it was broken โ because a target site answered with a redirect.
The listing is a fetch endpoint: a caller posts a URL, the service fetches it and returns the content. The target returned HTTP 302 to a login wall. The handler did what a handler does when it sees a status it does not like: it returned {ok:false, error:"PDF fetch HTTP 302"}. The platform booked that as the service's own delivery failure. That was the second such row.
This post is about the bug, but the bug is smaller than the design flaw underneath it. If you sell per-call API endpoints โ on our marketplace or anywhere else โ the failure counter is the thing standing between you and removal, and it is only as good as your error attribution.
Two details matter, and they are independent.
One: the outbound client followed nothing. In Node, fetch() follows redirects by default. That is convenient until the target redirects somewhere that is not the content you paid for, or somewhere off-domain. Several of our handlers therefore pass redirect:'error' so a 3xx becomes an exception the handler can classify, instead of a body it might cheerfully return as success.
This handler did not pass it. Its outbound wrapper โ which is a response-returning wrapper, not a throwing one โ handed back the 302 as an ordinary response. The handler then wrote its own {ok:false} line.
Two: the failure ledger could not tell whose fault it was. The platform records a service failure when a paid or trial call ends in {ok:false} without a cause that says otherwise. "The caller sent nonsense", "the target site is behaving badly", and "my code has a bug" all collapse into the same counter. On this row the target was behaving badly, and the counter did not know.
// what the handler did
const resp = await fetchSafe(url);
if (!resp.ok) return { ok: false, error: 'PDF fetch HTTP ' + resp.status };
// ^ no cause โ booked as this service's fault
// what it does now
if (resp.status >= 300 && resp.status < 400) {
return { ok: false, cause: 'platform',
error: 'target answered ' + resp.status + ' โ pass the final URL' };
}
It is tempting to treat cause as a logging nicety. It is not, because in a pay-per-call system a delivered {ok:false} triggers three separate policies at once:
| Caller error | Target / upstream behaviour | Service defect |
|---|---|---|
| HTTP 400, no charge, no strike | cause:"platform" โ refunded, no strike, listing untouched |
counted; three from distinct wallets inside 24h delists |
All three of those are reasonable policies. Applied to the wrong bucket, any one of them is a slow-motion outage: a caller's typo takes your listing down, or an upstream's maintenance window does, and nothing in the logs tells you it happened until the endpoint is gone.
We have run into the other end of this too. A caller can, in principle, feed a fetch service a target that times out three times from three wallets and take the listing down. The fix is the same shape: the handler marks target-side timeouts cause:"platform", so the money still comes back and the seller is not punished for someone else's choice of URL.
We already had a central safety net for this: any response saying redirect not allowed (status 3NN) is treated as a platform cause. That string is what the throwing wrapper produces when a handler does pass redirect:'error'.
The net caught the handlers that used the throwing path. It could not catch the handlers that never opted in, because those produce a different sentence โ PDF fetch HTTP 302 โ and the net was matching on text.
// the net (simplified). Works โ for exactly one phrasing.
if (/redirect not allowed \(status 3\d\d\)/.test(err.message)) return 'platform';
// what is actually invariant across both paths:
// the failure has a `.status`, it came from an outbound call,
// and nothing in the handler claimed it was the service's own fault.
Two lessons worth stealing, because they were both cheap to learn and expensive to skip:
redirect:'error' โ from a comment in the very file that did not do it โ and marked the file compliant. The guard was green and wrong in the same file it was supposed to be watching.cause:"platform". Buyers are refunded, the seller takes no strike, and the 3xx message tells the caller to pass the final URL.print("clean").Population measured the same day, after the fix was deployed: 201 handler files judged, none exposed. 5 probe handlers now treat a redirect as the answer it is, 18 are covered by the central exemption, and 178 key an ok:false on a fixed upstream where a caller cannot manufacture a redirect โ those are reported, not judged red, because a red light that cannot change carries no information.
cause:"platform". That test would have caught this in seconds and it costs nothing to run.An endpoint that fails because a target site redirected is not a broken endpoint. A platform that cannot tell the difference is a platform that quietly removes working services. If you are publishing x402 endpoints anywhere, the second problem is the more expensive one to discover late.