Skip to content

Always attach some URL/target data point to fetch/xhr/request errors #13168

Open

Description

@lforst

Description

The Sentry Chief Product Officer has brought to our attention that Fetch errors sometimes suck. (example that will expire in 90 days)

Image

We technically have a stack trace here but sourcemaps are broken so the user has basically no idea what fetch request failed. It's very hard to gauge from breadcrumbs what exact request failed.

Side note, the fetch call that failed looked like fetch(""). We render this as in the product, you guessed it "". Which is crap because it actually means the request went to the current route. We should at least coerce that string to URL(fetchTarget, window.location.href).toString() in the SDK.

Image

Activity

  1. kunal649 commented on Oct 20, 2026

    @kunal649
    Contributor

    Hii, i was working on this issue & i think there are two separate things going on;

    1. Message: enhanceFetchErrorMessages already appends the host, but it calls new URL(url) without a base, so relative URLs (including "") throw and are silently skipped.

    try {
    const url = new URL(handlerData.fetchData.url);
    const hostname = url.host;
    if (enhanceOption === 'always') {
    // Modify the error message directly
    error.message = `${error.message} (${hostname})`;
    } else {
    // Store hostname as non-enumerable property for Sentry-only enhancement
    // This preserves the original error message for third-party packages
    addNonEnumerableProperty(error, '__sentry_fetch_url_host__', hostname);
    }
    } catch {
    // ignore it if errors happen here
    }
    }

    I added test in core/test/lib/instrument/fetch.test.ts , it failed.
    Before:
    Image

    For this part I've made a PR - #25555 with 6 unit tests, (relative URL, empty URL, no location, file:// origin, opaque null origin, absolute URL on another origin) all passed.

    1. Breadcrumbs: The empty URL in breadcrumbs is a separate spot - "" is stored as-is in breadcrumbs.ts. Coercing it with new URL(target, location.href) would work, but since new URL('', base).href keeps the base’s query string (not the hash, that’s dropped), it would leak query params like ?token=... into the breadcrumb.
      want the full resolved URL anyway, or should the query be stripped before storing it?
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 20, 2026
  3. lforst commented on Oct 20, 2026

    @lforst
    ContributorAuthor

    big

  4. self-assigned this
    on Oct 20, 2026
  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions