Skip to content

Commit a1ecb49

Browse files
committed
Use makeDsn from core
1 parent aada963 commit a1ecb49

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

packages/core/src/js/sdk.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable complexity */
22
import type { Breadcrumb, BreadcrumbHint, Integration, Scope, SendFeedbackParams, UserFeedback } from '@sentry/core';
3-
import { captureFeedback, getClient, getGlobalScope, getIntegrationsToSetup, getIsolationScope, initAndBind, logger, stackParserFromStackParserOptions, withScope as coreWithScope } from '@sentry/core';
3+
import { captureFeedback, getClient, getGlobalScope, getIntegrationsToSetup, getIsolationScope, initAndBind, logger, makeDsn, stackParserFromStackParserOptions, withScope as coreWithScope } from '@sentry/core';
44
import {
55
defaultStackParser,
66
makeFetchTransport,
@@ -66,20 +66,13 @@ export function init(passedOptions: ReactNativeOptions): void {
6666
if (!dsn) {
6767
return undefined;
6868
}
69-
try {
70-
const regex = /^(https?):\/\/(?:[^@]+@)?([^/]+)(?:\/.*)?$/;
71-
const matches = dsn.match(regex);
72-
73-
if (matches) {
74-
const [, protocol, host] = matches;
75-
return `${protocol}://${host}`;
76-
}
69+
const dsnComponents = makeDsn(dsn);
70+
if (!dsnComponents) {
7771
logger.error('Failed to extract url from DSN: ', dsn);
7872
return undefined;
79-
} catch (e) {
80-
logger.error('Failed to extract url from DSN', e);
81-
return undefined;
8273
}
74+
const port = dsnComponents.port ? `:${dsnComponents.port}` : '';
75+
return `${dsnComponents.protocol}://${dsnComponents.host}${port}`;
8376
};
8477

8578
const userBeforeBreadcrumb = safeFactory(passedOptions.beforeBreadcrumb, { loggerMessage: 'The beforeBreadcrumb threw an error' });

0 commit comments

Comments
 (0)