|
1 | 1 | /* 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'; |
3 | 3 | import { |
4 | 4 | addExceptionMechanism, |
5 | 5 | addInstrumentationHandler, |
@@ -100,14 +100,7 @@ function _installGlobalOnErrorHandler(hub: Hub, attachStacktrace: boolean | unde |
100 | 100 | data.column, |
101 | 101 | ); |
102 | 102 |
|
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'); |
111 | 104 | }, |
112 | 105 | type: 'error', |
113 | 106 | }); |
@@ -153,15 +146,7 @@ function _installGlobalOnUnhandledRejectionHandler(hub: Hub, attachStacktrace: b |
153 | 146 |
|
154 | 147 | event.level = Severity.Error; |
155 | 148 |
|
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'); |
165 | 150 | return; |
166 | 151 | }, |
167 | 152 | type: 'unhandledrejection', |
@@ -248,3 +233,13 @@ function _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column |
248 | 233 | function globalHandlerLog(type: string): void { |
249 | 234 | logger.log(`Global Handler attached: ${type}`); |
250 | 235 | } |
| 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