Skip to content

Commit

Permalink
ref(dsn): improve invalid dsn error message (#4430)
Browse files Browse the repository at this point in the history
  • Loading branch information
Badisi committed Jan 20, 2022
1 parent 3f2bf69 commit ff923f9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/utils/src/dsn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function dsnFromString(str: string): DsnComponents {
const match = DSN_REGEX.exec(str);

if (!match) {
throw new SentryError('Invalid Dsn');
throw new SentryError(`Invalid Sentry Dsn: ${str}`);
}

const [protocol, publicKey, pass = '', host, port = '', lastPath] = match.slice(1);
Expand Down Expand Up @@ -82,20 +82,20 @@ function validateDsn(dsn: DsnComponents): boolean | void {
const requiredComponents: ReadonlyArray<keyof DsnComponents> = ['protocol', 'publicKey', 'host', 'projectId'];
requiredComponents.forEach(component => {
if (!dsn[component]) {
throw new SentryError(`Invalid Dsn: ${component} missing`);
throw new SentryError(`Invalid Sentry Dsn: ${component} missing`);
}
});

if (!projectId.match(/^\d+$/)) {
throw new SentryError(`Invalid Dsn: Invalid projectId ${projectId}`);
throw new SentryError(`Invalid Sentry Dsn: Invalid projectId ${projectId}`);
}

if (!isValidProtocol(protocol)) {
throw new SentryError(`Invalid Dsn: Invalid protocol ${protocol}`);
throw new SentryError(`Invalid Sentry Dsn: Invalid protocol ${protocol}`);
}

if (port && isNaN(parseInt(port, 10))) {
throw new SentryError(`Invalid Dsn: Invalid port ${port}`);
throw new SentryError(`Invalid Sentry Dsn: Invalid port ${port}`);
}

return true;
Expand Down

0 comments on commit ff923f9

Please sign in to comment.