Repository navigation
fix(prerender): keep the headers of the http error the fetch got - #317
Conversation
When prerender throws and the fetch it ran alongside failed with an http error, the fallback took the status code from the error but read headers from a field the reflected failure never carried, so every header was dropped. A Cloudflare challenge then reached the caller as a bare 403: is-antibot saw statusCode=403 without cf-mitigated and detected nothing, so no retry ran (canva.link from datacenter IPs, 2026-11-21). The reflected failure now carries the same url, headers and status code as the unreflected one, and the fallback reads them from there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
html-get
Details
| Benchmark suite | Current: 348eb36 | Previous: c356aed | Ratio |
|---|---|---|---|
html rewriteUrls off |
119.5 ms (114-124.7) |
119.8 ms (114.2-124.8) |
1.00 |
html rewriteUrls on |
168.8 ms (167-179.8) |
166.4 ms (159.4-166.6) |
1.01 |
pdf extract |
89.4 ms (88.8-91.2) |
88.8 ms (88.3-90.7) |
1.01 |
cold require |
201.3 ms (199.6-202.5) |
202 ms (200.9-202.8) |
1.00 |
This comment was automatically generated by workflow using github-action-benchmark.
A connection failure must keep an empty headers object, an HTTP error must drop its body, and a prerender throw must return a successful fetch instead of an empty page.
When prerender throws (
empty response) and the fetch it ran alongside failed with an HTTP error, the fallback tookstatusCodefromerror.responsebut readheadersfrom a field the reflected failure never carried, so the result hadheaders: {}.Seen in production on 2026-11-21: Canva answers our datacenter IPs
403+cf-mitigated: challenge. The API loggedis-antibot:info no challenge detected ... statusCode=403 provider=null, ran no retry, and served the 403 page asstatus: successwithimage: null. With the header present, is-antibot detects Cloudflare from headers alone.The reflected failure now carries the same
url,headersandstatusCodeas the unreflected one, and the fallback reads them from there.Test:
a failed prerender keeps the headers of the http error the fetch gotintest/mode.jsfails without the change and passes with it. The full suite passes apart from 13 PDF tests that fail the same way on unmodified master on my machine.🤖 Generated with Claude Code
Note
Medium Risk
Touches core fetch/prerender error paths used in production antibot and fallback behavior, but the change is narrow and well covered by new tests.
Overview
Fixes a gap where parallel reflect fetch failures only surfaced
urlandstatusCode, so when prerender fell back after a failed fetch the result had emptyheadersand antibot logic (e.g. Cloudflarecf-mitigated) could not run.Fetch error handling now builds a shared
answer(url,headers,statusCode) for both reflected and normal failures. The prerender rejection path usesdata.headersanddata.statusCodefrom that payload instead oferror.response/ defaults.New tests cover header preservation on failed prerender + HTTP error, successful fetch fallback when browserless throws, connection failures, and stripping error response bodies from fetch HTML.
Reviewed by Cursor Bugbot for commit 348eb36. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit