File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,8 @@ function extractHttpModuleError(error: HttpErrorResponse): string | Error {
39
39
}
40
40
41
41
// ... or an`ErrorEvent`, which can provide us with the message but no stack...
42
- if ( error . error instanceof ErrorEvent && error . error . message ) {
42
+ // guarding `ErrorEvent` against `undefined` as it's not defined in Node environments
43
+ if ( typeof ErrorEvent !== 'undefined' && error . error instanceof ErrorEvent && error . error . message ) {
43
44
return error . error . message ;
44
45
}
45
46
Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ describe('SentryErrorHandler', () => {
45
45
} ) ;
46
46
47
47
describe ( 'handleError method' , ( ) => {
48
+ const originalErrorEvent = globalThis . ErrorEvent ;
49
+ afterEach ( ( ) => {
50
+ globalThis . ErrorEvent = originalErrorEvent ;
51
+ } ) ;
52
+
48
53
it ( 'extracts `null` error' , ( ) => {
49
54
createErrorHandler ( ) . handleError ( null ) ;
50
55
@@ -223,6 +228,18 @@ describe('SentryErrorHandler', () => {
223
228
expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( 'Handled unknown error' , captureExceptionEventHint ) ;
224
229
} ) ;
225
230
231
+ it ( 'handles ErrorEvent being undefined' , ( ) => {
232
+ const httpErr = new ErrorEvent ( 'http' , { message : 'sentry-http-test' } ) ;
233
+ const err = new HttpErrorResponse ( { error : httpErr } ) ;
234
+
235
+ // @ts -expect-error - this is fine in this test
236
+ delete globalThis . ErrorEvent ;
237
+
238
+ expect ( ( ) => {
239
+ createErrorHandler ( ) . handleError ( err ) ;
240
+ } ) . not . toThrow ( ) ;
241
+ } ) ;
242
+
226
243
it ( 'extracts an Error with `ngOriginalError`' , ( ) => {
227
244
const ngErr = new Error ( 'sentry-ng-test' ) ;
228
245
const err = {
You can’t perform that action at this time.
0 commit comments