Skip to content

Commit da16a85

Browse files
logaretmclaude
andcommitted
ref(browser-utils): Use safeCallback for route provider calls
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b28ceda commit da16a85

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

‎packages/browser-utils/src/routing.ts‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Client } from '@sentry/core';
2-
import { debug, getClient, LRUMap, parseStringToURLObject } from '@sentry/core';
2+
import { debug, getClient, LRUMap, parseStringToURLObject, safeCallback } from '@sentry/core';
33
import { DEBUG_BUILD } from './debug-build';
44
import { getLocationHref } from './getLocationHref';
55

@@ -12,8 +12,6 @@ type RouteUrl = Pick<URL, 'pathname' | 'search' | 'hash'>;
1212
* Framework SDKs register one so that everything the SDK names after a route (span names, the scope's
1313
* transaction name, metric and span segment attributes) gets the parameterized route instead of the raw
1414
* URL, without each integration having to reach into the framework's router itself.
15-
*
16-
* A provider only answers "which route is this", never what the caller does with the answer.
1715
*/
1816
export interface RouteProvider {
1917
/**
@@ -170,10 +168,9 @@ function parseLocation(url: string): RouteUrl | undefined {
170168
* was naming.
171169
*/
172170
function callProvider(resolve: () => string | undefined): string | undefined {
173-
try {
174-
return resolve() || undefined;
175-
} catch (error) {
176-
DEBUG_BUILD && debug.warn('Route provider threw while resolving a route:', error);
177-
return undefined;
178-
}
171+
return safeCallback(
172+
DEBUG_BUILD ? 'Route provider threw while resolving a route:' : '',
173+
() => resolve() || undefined,
174+
() => undefined,
175+
);
179176
}

0 commit comments

Comments
 (0)