File tree 2 files changed +28
-1
lines changed 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,18 @@ function streamFromBody(body: Uint8Array | string): Readable {
47
47
* Creates a Transport that uses native the native 'http' and 'https' modules to send events to Sentry.
48
48
*/
49
49
export function makeNodeTransport ( options : NodeTransportOptions ) : Transport {
50
- const urlSegments = new URL ( options . url ) ;
50
+ let urlSegments : URL ;
51
+
52
+ try {
53
+ urlSegments = new URL ( options . url ) ;
54
+ } catch ( e ) {
55
+ // eslint-disable-next-line no-console
56
+ console . warn (
57
+ '[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.' ,
58
+ ) ;
59
+ return createTransport ( options , ( ) => Promise . resolve ( { } ) ) ;
60
+ }
61
+
51
62
const isHttps = urlSegments . protocol === 'https:' ;
52
63
53
64
// Proxy prioritization: http => `options.proxy` | `process.env.http_proxy`
Original file line number Diff line number Diff line change @@ -399,4 +399,20 @@ describe('makeNewHttpTransport()', () => {
399
399
) ;
400
400
} ) ;
401
401
} ) ;
402
+
403
+ it ( 'should create a noop transport if an invalid url is passed' , async ( ) => {
404
+ const requestSpy = jest . spyOn ( http , 'request' ) ;
405
+ const transport = makeNodeTransport ( { ...defaultOptions , url : 'foo' } ) ;
406
+ await transport . send ( EVENT_ENVELOPE ) ;
407
+ expect ( requestSpy ) . not . toHaveBeenCalled ( ) ;
408
+ } ) ;
409
+
410
+ it ( 'should warn if an invalid url is passed' , async ( ) => {
411
+ const consoleWarnSpy = jest . spyOn ( console , 'warn' ) ;
412
+ const transport = makeNodeTransport ( { ...defaultOptions , url : 'invalid url' } ) ;
413
+ await transport . send ( EVENT_ENVELOPE ) ;
414
+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
415
+ '[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.' ,
416
+ ) ;
417
+ } ) ;
402
418
} ) ;
You can’t perform that action at this time.
0 commit comments