Repository navigation
fix(core): Resolve relative URLs when enhancing fetch error messages - #25555
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit efe30f6. Configure here.
s1gr1d
left a comment
There was a problem hiding this comment.
Thank you so much for picking this up!
a small nit regarding the tests: they are all quite similar so you could use an it.each there, like this:
it.each([
['a relative path', 'https://app.example.com/dashboard?tab=billing', '/api/users/42', 'Failed to fetch (app.example.com)'],
])('resolves %s against location.href', async (_name, href, target, expected) => {}efe30f6 to
dc615b1
Compare
s1gr1d
left a comment
There was a problem hiding this comment.
Looks good now, thank you!
A few small things:
- Can you update the description so it mentions
href? - We should rename
Fixes #13168->Ref #13168. This PR covers the fetch error message, but the issue also mentions XHR and the empty URL in breadcrumbs, so we should keep that open
dc615b1 to
e776589
Compare
Done, sigrid |
e776589 to
21feeb1
Compare
…nd an absolute URL on a different origin than the page
21feeb1 to
6478625
Compare
|
please excuse the chaotic force-push history, just had boss-fight with git rebase🙂 |
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #25555 Co-authored-by: s1gr1d <32902192+s1gr1d@users.noreply.github.com> Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>

enhanceFetchErrorMessagesalready adds the host to generic fetch errors, soFailed to fetchbecomesFailed to fetch (example.com). The catch is that it rannew URL(url)with no base, and that throws for relative URLs like/api/fooor thefetch("")from the issue. The try/catch swallowed the error, so those requests never got the host.Now relative URLs are resolved against
location.hrefinstead of origin to safely handle sandboxed iframes and opaque origins without throwing. Absolute URLs ignore the base, and where there's nolocation(Node, workers) nothing changes. I also skip the enhancement when the resolved host is empty, like onfile://pages, otherwise you'd getFailed to fetch ().locationis added toInternalGlobalfor the typing.Added 7 unit tests (relative URL, empty URL, no
location,file://origin, a relative path & an absolute URL in sandboxed srcdoc iframe , absolute URL on another origin).This only touches the error message. The empty URL in the fetch breadcrumbs is a separate spot, so I left it out to discuss on the issue thread.
Ref #13168