Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/node/src/transports/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,18 @@ function streamFromBody(body: Uint8Array | string): Readable {
* Creates a Transport that uses native the native 'http' and 'https' modules to send events to Sentry.
*/
export function makeNodeTransport(options: NodeTransportOptions): Transport {
const urlSegments = new URL(options.url);
let urlSegments: URL;

try {
urlSegments = new URL(options.url);
} catch (e) {
// eslint-disable-next-line no-console
console.warn(
'[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.',
);
return createTransport(options, () => Promise.resolve({}));
}

const isHttps = urlSegments.protocol === 'https:';

// Proxy prioritization: http => `options.proxy` | `process.env.http_proxy`
Expand Down
16 changes: 16 additions & 0 deletions packages/node/test/transports/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,20 @@ describe('makeNewHttpTransport()', () => {
);
});
});

it('should create a noop transport if an invalid url is passed', async () => {
const requestSpy = jest.spyOn(http, 'request');
const transport = makeNodeTransport({ ...defaultOptions, url: 'foo' });
await transport.send(EVENT_ENVELOPE);
expect(requestSpy).not.toHaveBeenCalled();
});

it('should warn if an invalid url is passed', async () => {
const consoleWarnSpy = jest.spyOn(console, 'warn');
const transport = makeNodeTransport({ ...defaultOptions, url: 'invalid url' });
await transport.send(EVENT_ENVELOPE);
expect(consoleWarnSpy).toHaveBeenCalledWith(
'[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.',
);
});
});