Skip to content

fix(fetch): report the url that answered an http error - #316

Merged
Kikobeats merged 3 commits into
masterfrom
Kikobeats/fetch-error-response-url
Nov 19, 2026
Merged

Kikobeats merged 3 commits into
masterfrom
Kikobeats/fetch-error-response-url

Conversation

@Kikobeats

@Kikobeats Kikobeats commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

What

In fetch mode, a redirect chain that ends on a 4xx/5xx reported the requested url instead of the url that answered. Prerender mode already reported response.url(), so both modes now agree.

/blocked -> 302 -> /denied (403)
before: fetch url=/blocked, prerender url=/denied
after:  both url=/denied, redirects=[{302, /blocked}]

Why

microlink-api (issue microlink/api#19) returns redirects: [] for https://dub.sh/twitter-redirect because the winning hop goes through scrape.do, which follows redirects itself. The API takes the redirect chain from its origin probe, but only when the probe ended at the same url as the proxied hop. That probe ends on x.com's antibot wall (an http error), where html-get reported the shortener url, so the check can never match.

Tests

  • test/url.js: {fetch,prerender} » a redirect to an error page reports the url that answered. It failed in fetch mode before the fix and passes in both modes after.
  • test/url.js, test/redirects.js, test/mode.js: 26 passed.
  • test/pdf/**: 12 snapshot failures locally, the same 12 on origin/master (local mutool output), so they are unrelated.

🤖 Generated with Claude Code


Note

Low Risk
Behavior change is limited to error/redirect edge cases in returned metadata; successful fetches are unchanged, but callers that relied on the old (incorrect) URL on errors may see different values.

Overview
Fetch mode now returns the final response URL on HTTP errors (from error.response.url when present), instead of the originally requested URL. That aligns fetch with prerender’s response.url() behavior when a redirect chain ends on a 4xx/5xx.

When prerender falls back after a rejected fetch, the error payload uses data.url from the fetch result rather than the input URL.

New tests cover redirect-to-error (fetch + prerender), prerender browser failure, and connection failure still reporting the requested URL when there is no response.

Reviewed by Cursor Bugbot for commit ca9c397. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Fetch errors now report the final response URL when available, or the requested URL when it isn’t.
    • Redirects that end at an error page now report the URL that returned the error.
    • Failed prerender results now use the URL reported by the fetch result. Existing fallback behavior for prerendered 4xx responses is unchanged.

When a redirect chain ends on a 4xx/5xx, got rejects and the fetch branch
reported the requested url instead of the one that answered. The redirects
were right and the prerender branch already used response.url(), so the
two modes disagreed on the same chain: /blocked -> 302 -> /denied (403)
came back as url /blocked in fetch mode and /denied in prerender mode.

microlink-api needs the real final url of an origin probe that ended on
an antibot wall to tell whether a proxied hop landed on the same page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Fetch errors now report the response URL when available, or the requested URL otherwise. Prerender fallback results use the fetch result’s URL. Tests cover redirects to an HTTP 403 response and fetch connection failures.

Changes: Redirect error URL

Layer / File(s) Summary
Report and verify the error response URL
src/index.js, test/url.js
Fetch-error results use the response URL when available, and prerender fallback results use the fetch result’s URL. Tests check the URL and redirect record for a 403 response in fetch and prerender modes, and verify the requested URL for a connection failure.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • microlinkhq/html-get#309: Both PRs change the URL reported for fetch-mode redirects and add related cases to test/url.js.
Merge Risk: Minimal · up to ca9c3

Fetch and prerender now report the URL that actually answered an HTTP error after redirects, and the previous fallback is kept when there is no response. The change is small and tested, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(fetch): report the url that answered an http error" matches the main change. The raw summary and objectives both say fetch and prerender now report the URL that answered when an HTTP er…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(fetch): report the url that answered an http error" matches the main change. The raw summary and objectives both say fetch and prerender now report the URL that answered when an HTTP error follows redirects, and the tests cover this behavior. The title is specific and short, and it uses the conventional commit prefix.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ac5eb1d0-2d61-4231-b705-0662452cbdfe
Commits

Reviewing files that changed from the base of the PR and between ccdfdff and ca9c397.

Files selected for processing: 1

  • test/url.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

html-get

Details
Benchmark suite Current: ca9c397 Previous: 15f2dc6 Ratio
html rewriteUrls off 138.8 ms (137.3-141.7) 141.9 ms (136.2-151.2) 0.98
html rewriteUrls on 212.4 ms (204-220.6) 212 ms (209.4-217.1) 1.00
pdf extract 99.5 ms (96-104) 97.5 ms (96-99.7) 1.02
cold require 244.8 ms (242.8-247.2) 243.7 ms (241.9-245.5) 1.00

This comment was automatically generated by workflow using github-action-benchmark.

A browser failure kept the request url while statusCode came from the page that answered the redirect.
Comparing the two modes stayed green when that fallback changed, because both modes now share it.
@Kikobeats
Kikobeats merged commit 5392bc2 into master Nov 19, 2026
5 checks passed
@Kikobeats
Kikobeats deleted the Kikobeats/fetch-error-response-url branch November 19, 2026 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant