MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / validateDsn

Function validateDsn

packages/core/src/utils/dsn.ts:83–119  ·  view source on GitHub ↗
(dsn: DsnComponents)

Source from the content-addressed store, hash-verified

81}
82
83function validateDsn(dsn: DsnComponents): boolean {
84 if (!DEBUG_BUILD) {
85 return true;
86 }
87
88 const { port, projectId, protocol } = dsn;
89
90 const requiredComponents: ReadonlyArray<keyof DsnComponents> = ['protocol', 'publicKey', 'host', 'projectId'];
91 const hasMissingRequiredComponent = requiredComponents.find(component => {
92 if (!dsn[component]) {
93 debug.error(`Invalid Sentry Dsn: ${component} missing`);
94 return true;
95 }
96 return false;
97 });
98
99 if (hasMissingRequiredComponent) {
100 return false;
101 }
102
103 if (!projectId.match(/^\d+$/)) {
104 debug.error(`Invalid Sentry Dsn: Invalid projectId ${projectId}`);
105 return false;
106 }
107
108 if (!isValidProtocol(protocol)) {
109 debug.error(`Invalid Sentry Dsn: Invalid protocol ${protocol}`);
110 return false;
111 }
112
113 if (port && isNaN(parseInt(port, 10))) {
114 debug.error(`Invalid Sentry Dsn: Invalid port ${port}`);
115 return false;
116 }
117
118 return true;
119}
120
121/**
122 * Extract the org ID from a DSN host.

Callers 1

makeDsnFunction · 0.85

Calls 3

isValidProtocolFunction · 0.85
matchMethod · 0.80
errorMethod · 0.65

Tested by

no test coverage detected