Skip to content

Commit d0edcd9

Browse files
committed
refactor logic into one function
1 parent 91f0724 commit d0edcd9

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2-
import { Event, EventProcessor, Hub, Integration, Primitive, Severity } from '@sentry/types';
2+
import { Event, EventProcessor, Hub, Integration, Primitive, Severity, EventHint } from '@sentry/types';
33
import {
44
addExceptionMechanism,
55
addInstrumentationHandler,
@@ -100,14 +100,7 @@ function _installGlobalOnErrorHandler(hub: Hub, attachStacktrace: boolean | unde
100100
data.column,
101101
);
102102

103-
addExceptionMechanism(event, {
104-
handled: false,
105-
type: 'onerror',
106-
});
107-
108-
hub.captureEvent(event, {
109-
originalException: error,
110-
});
103+
addMechanismAndCapture(hub, error, event, 'onerror');
111104
},
112105
type: 'error',
113106
});
@@ -153,15 +146,7 @@ function _installGlobalOnUnhandledRejectionHandler(hub: Hub, attachStacktrace: b
153146

154147
event.level = Severity.Error;
155148

156-
addExceptionMechanism(event, {
157-
handled: false,
158-
type: 'onunhandledrejection',
159-
});
160-
161-
hub.captureEvent(event, {
162-
originalException: error,
163-
});
164-
149+
addMechanismAndCapture(hub, error, event, 'onunhandledrejection');
165150
return;
166151
},
167152
type: 'unhandledrejection',
@@ -248,3 +233,13 @@ function _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column
248233
function globalHandlerLog(type: string): void {
249234
logger.log(`Global Handler attached: ${type}`);
250235
}
236+
237+
function addMechanismAndCapture(hub: Hub, error: EventHint['originalException'], event: Event, type: string): void {
238+
addExceptionMechanism(event, {
239+
handled: false,
240+
type,
241+
});
242+
hub.captureEvent(event, {
243+
originalException: error,
244+
});
245+
}

0 commit comments

Comments
 (0)