File tree Expand file tree Collapse file tree 4 files changed +56
-16
lines changed Expand file tree Collapse file tree 4 files changed +56
-16
lines changed Original file line number Diff line number Diff line change @@ -79,15 +79,6 @@ export function init(options: NextjsOptions): void {
79
79
const activeDomain = domain . active ;
80
80
domain . active = null ;
81
81
82
- if ( typeof options . tunnel !== 'undefined' ) {
83
- try {
84
- new URL ( options . tunnel ) ;
85
- } catch ( error ) {
86
- __DEBUG_BUILD__ &&
87
- logger . error ( 'The tunnel option is not a valid URL. It must be a full URL including the protocol.' ) ;
88
- throw new Error ( 'The tunnel option is not a valid URL. It must be a full URL including the protocol.' ) ;
89
- }
90
- }
91
82
nodeInit ( options ) ;
92
83
93
84
const filterTransactions : EventProcessor = event => {
Original file line number Diff line number Diff line change @@ -140,21 +140,29 @@ describe('Server init()', () => {
140
140
} ) ;
141
141
142
142
it ( 'should not fail on valid tunnel option' , ( ) => {
143
+ const consoleWarnSpy = jest . spyOn ( console , 'warn' ) ;
143
144
expect ( ( ) =>
144
145
init ( {
145
146
dsn : 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012' ,
146
147
tunnel : 'https://example.com/api' ,
147
148
} ) ,
148
149
) . not . toThrowError ( ) ;
150
+ expect ( consoleWarnSpy ) . not . toHaveBeenCalledWith (
151
+ 'The tunnel option is not a valid URL. It must be a full URL including the protocol when using the Node transport.' ,
152
+ ) ;
149
153
} ) ;
150
154
151
- it ( 'should fail on invalid tunnel option' , ( ) => {
152
- expect ( ( ) =>
153
- init ( {
154
- dsn : 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012' ,
155
- tunnel : '/invalid' ,
156
- } ) ,
157
- ) . toThrowError ( 'The tunnel option is not a valid URL. It must be a full URL including the protocol.' ) ;
155
+ it ( 'should not fail on invalid tunnel option' , ( ) => {
156
+ const consoleWarnSpy = jest . spyOn ( console , 'warn' ) ;
157
+
158
+ init ( {
159
+ dsn : 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012' ,
160
+ tunnel : '/invalid' ,
161
+ } ) ;
162
+
163
+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
164
+ 'The tunnel option is not a valid URL. It must be a full URL including the protocol when using the Node transport.' ,
165
+ ) ;
158
166
} ) ;
159
167
160
168
describe ( 'integrations' , ( ) => {
Original file line number Diff line number Diff line change @@ -157,6 +157,8 @@ export function init(options: NodeOptions = {}): void {
157
157
setHubOnCarrier ( carrier , getCurrentHub ( ) ) ;
158
158
}
159
159
160
+ checkNodeTunnelOption ( options ) ;
161
+
160
162
// TODO(v7): Refactor this to reduce the logic above
161
163
const clientOptions : NodeClientOptions = {
162
164
...options ,
@@ -172,6 +174,20 @@ export function init(options: NodeOptions = {}): void {
172
174
}
173
175
}
174
176
177
+ function checkNodeTunnelOption ( options : NodeOptions = { } ) : void {
178
+ if ( options . tunnel !== undefined ) {
179
+ try {
180
+ new URL ( options . tunnel ) ;
181
+ } catch ( error ) {
182
+ // eslint-disable-next-line no-console
183
+ console . warn (
184
+ 'The tunnel option is not a valid URL. It must be a full URL including the protocol when using the Node transport.' ,
185
+ ) ;
186
+ options . tunnel = undefined ;
187
+ }
188
+ }
189
+ }
190
+
175
191
/**
176
192
* This is the getter for lastEventId.
177
193
*
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ const defaultIntegrationsBackup = sdk.defaultIntegrations;
20
20
21
21
describe ( 'init()' , ( ) => {
22
22
beforeEach ( ( ) => {
23
+ jest . clearAllMocks ( ) ;
23
24
global . __SENTRY__ = { } ;
24
25
} ) ;
25
26
@@ -89,4 +90,28 @@ describe('init()', () => {
89
90
expect ( mockDefaultIntegrations [ 1 ] . setupOnce as jest . Mock ) . toHaveBeenCalledTimes ( 0 ) ;
90
91
expect ( newIntegration . setupOnce as jest . Mock ) . toHaveBeenCalledTimes ( 1 ) ;
91
92
} ) ;
93
+
94
+ it ( 'should not error on valid tunnel option' , ( ) => {
95
+ const consoleWarnSpy = jest . spyOn ( console , 'warn' ) ;
96
+ expect ( ( ) =>
97
+ init ( {
98
+ dsn : 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012' ,
99
+ tunnel : 'https://example.com/api' ,
100
+ } ) ,
101
+ ) . not . toThrowError ( ) ;
102
+ expect ( consoleWarnSpy ) . not . toHaveBeenCalledWith (
103
+ 'The tunnel option is not a valid URL. It must be a full URL including the protocol when using the Node transport.' ,
104
+ ) ;
105
+ } ) ;
106
+
107
+ it ( 'should not error on invalid tunnel option' , ( ) => {
108
+ const consoleWarnSpy = jest . spyOn ( console , 'warn' ) ;
109
+ init ( {
110
+ dsn : 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012' ,
111
+ tunnel : '/invalid' ,
112
+ } ) ;
113
+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
114
+ 'The tunnel option is not a valid URL. It must be a full URL including the protocol when using the Node transport.' ,
115
+ ) ;
116
+ } ) ;
92
117
} ) ;
You can’t perform that action at this time.
0 commit comments