Skip to content

Commit c7060f0

Browse files
committed
fix(core): Resolve relative URLs when enhancing fetch error messages
1 parent 46f136a commit c7060f0

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

‎packages/core/src/instrument/fetch.ts‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,18 @@ function instrumentFetch(onFetchResolved?: (response: Response) => void): void {
136136
error.message === 'NetworkError when attempting to fetch resource.')
137137
) {
138138
try {
139-
const url = new URL(handlerData.fetchData.url);
139+
const url = new URL(handlerData.fetchData.url, GLOBAL_OBJ.location?.origin);
140140
const hostname = url.host;
141141

142-
if (enhanceOption === 'always') {
143-
// Modify the error message directly
144-
error.message = `${error.message} (${hostname})`;
145-
} else {
146-
// Store hostname as non-enumerable property for Sentry-only enhancement
147-
// This preserves the original error message for third-party packages
148-
addNonEnumerableProperty(error, '__sentry_fetch_url_host__', hostname);
142+
if (hostname) {
143+
if (enhanceOption === 'always') {
144+
// Modify the error message directly
145+
error.message = `${error.message} (${hostname})`;
146+
} else {
147+
// Store hostname as non-enumerable property for Sentry-only enhancement
148+
// This preserves the original error message for third-party packages
149+
addNonEnumerableProperty(error, '__sentry_fetch_url_host__', hostname);
150+
}
149151
}
150152
} catch {
151153
// ignore it if errors happen here

‎packages/core/src/utils/worldwide.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type { SdkSource } from './env';
1919
/** Internal global with common properties and Sentry extensions */
2020
export type InternalGlobal = {
2121
navigator?: { userAgent?: string; maxTouchPoints?: number };
22+
location?: { origin?: string };
2223
console: Console;
2324
PerformanceObserver?: any;
2425
Sentry?: any;

0 commit comments

Comments
 (0)