@@ -4,6 +4,9 @@ import { SentryError } from '@sentry/utils/error';
44/** Regular expression used to parse a Dsn. */
55const DSN_REGEX = / ^ (?: ( \w + ) : ) \/ \/ (?: ( \w + ) (?: : ( \w + ) ) ? @ ) ( [ \w \. - ] + ) (?: : ( \d + ) ) ? \/ ( .+ ) / ;
66
7+ /** Error message */
8+ const ERROR_MESSAGE = 'Invalid Dsn' ;
9+
710/** The Sentry Dsn, identifying a Sentry instance and project. */
811export class Dsn implements DsnComponents {
912 /** Protocol used to connect to Sentry. */
@@ -54,7 +57,7 @@ export class Dsn implements DsnComponents {
5457 private fromString ( str : string ) : void {
5558 const match = DSN_REGEX . exec ( str ) ;
5659 if ( ! match ) {
57- throw new SentryError ( 'Invalid Dsn' ) ;
60+ throw new SentryError ( ERROR_MESSAGE ) ;
5861 }
5962
6063 const [ protocol , user , pass = '' , host , port = '' , lastPath ] = match . slice ( 1 ) ;
@@ -81,18 +84,18 @@ export class Dsn implements DsnComponents {
8184
8285 /** Validates this Dsn and throws on error. */
8386 private validate ( ) : void {
84- for ( const component of [ 'protocol' , 'user' , 'host' , 'projectId' ] ) {
87+ [ 'protocol' , 'user' , 'host' , 'projectId' ] . forEach ( component => {
8588 if ( ! this [ component as keyof DsnComponents ] ) {
86- throw new SentryError ( `Invalid Dsn: Missing ${ component } ` ) ;
89+ throw new SentryError ( ERROR_MESSAGE ) ;
8790 }
88- }
91+ } ) ;
8992
9093 if ( this . protocol !== 'http' && this . protocol !== 'https' ) {
91- throw new SentryError ( `Invalid Dsn: Unsupported protocol " ${ this . protocol } "` ) ;
94+ throw new SentryError ( ERROR_MESSAGE ) ;
9295 }
9396
9497 if ( this . port && Number . isNaN ( parseInt ( this . port , 10 ) ) ) {
95- throw new SentryError ( `Invalid Dsn: Invalid port number " ${ this . port } "` ) ;
98+ throw new SentryError ( ERROR_MESSAGE ) ;
9699 }
97100 }
98101}
0 commit comments