1- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2- import { captureEvent , convertIntegrationFnToClass , defineIntegration , getClient } from '@sentry/core' ;
3- import type {
4- Client ,
5- Event ,
6- Integration ,
7- IntegrationClass ,
8- IntegrationFn ,
9- Primitive ,
10- StackParser ,
11- } from '@sentry/types' ;
1+ import { captureEvent , defineIntegration , getClient } from '@sentry/core' ;
2+ import type { Client , Event , IntegrationFn , Primitive , StackParser } from '@sentry/types' ;
123import {
134 addGlobalErrorInstrumentationHandler ,
145 addGlobalUnhandledRejectionInstrumentationHandler ,
156 getLocationHref ,
16- isErrorEvent ,
177 isPrimitive ,
188 isString ,
199 logger ,
@@ -57,18 +47,6 @@ const _globalHandlersIntegration = ((options: Partial<GlobalHandlersIntegrations
5747
5848export const globalHandlersIntegration = defineIntegration ( _globalHandlersIntegration ) ;
5949
60- /**
61- * Global handlers.
62- * @deprecated Use `globalHandlersIntegration()` instead.
63- */
64- // eslint-disable-next-line deprecation/deprecation
65- export const GlobalHandlers = convertIntegrationFnToClass (
66- INTEGRATION_NAME ,
67- globalHandlersIntegration ,
68- ) as IntegrationClass < Integration & { setup : ( client : Client ) => void } > & {
69- new ( options ?: Partial < GlobalHandlersIntegrations > ) : Integration ;
70- } ;
71-
7250function _installGlobalOnErrorHandler ( client : Client ) : void {
7351 addGlobalErrorInstrumentationHandler ( data => {
7452 const { stackParser, attachStacktrace } = getOptions ( ) ;
@@ -79,15 +57,12 @@ function _installGlobalOnErrorHandler(client: Client): void {
7957
8058 const { msg, url, line, column, error } = data ;
8159
82- const event =
83- error === undefined && isString ( msg )
84- ? _eventFromIncompleteOnError ( msg , url , line , column )
85- : _enhanceEventWithInitialFrame (
86- eventFromUnknownInput ( stackParser , error || msg , undefined , attachStacktrace , false ) ,
87- url ,
88- line ,
89- column ,
90- ) ;
60+ const event = _enhanceEventWithInitialFrame (
61+ eventFromUnknownInput ( stackParser , error || msg , undefined , attachStacktrace , false ) ,
62+ url ,
63+ line ,
64+ column ,
65+ ) ;
9166
9267 event . level = 'error' ;
9368
@@ -132,24 +107,23 @@ function _getUnhandledRejectionError(error: unknown): unknown {
132107 return error ;
133108 }
134109
135- // eslint-disable-next-line @typescript-eslint/no-explicit-any
136- const e = error as any ;
137-
138110 // dig the object of the rejection out of known event types
139111 try {
112+ type ErrorWithReason = { reason : unknown } ;
140113 // PromiseRejectionEvents store the object of the rejection under 'reason'
141114 // see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
142- if ( 'reason' in e ) {
143- return e . reason ;
115+ if ( 'reason' in ( error as ErrorWithReason ) ) {
116+ return ( error as ErrorWithReason ) . reason ;
144117 }
145118
119+ type CustomEventWithDetail = { detail : { reason : unknown } } ;
146120 // something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
147121 // to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
148122 // the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
149123 // see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
150124 // https://github.com/getsentry/sentry-javascript/issues/2380
151- else if ( 'detail' in e && 'reason' in e . detail ) {
152- return e . detail . reason ;
125+ if ( 'detail' in ( error as CustomEventWithDetail ) && 'reason' in ( error as CustomEventWithDetail ) . detail ) {
126+ return ( error as CustomEventWithDetail ) . detail . reason ;
153127 }
154128 } catch { } // eslint-disable-line no-empty
155129
@@ -176,38 +150,6 @@ function _eventFromRejectionWithPrimitive(reason: Primitive): Event {
176150 } ;
177151}
178152
179- /**
180- * This function creates a stack from an old, error-less onerror handler.
181- */
182- // eslint-disable-next-line @typescript-eslint/no-explicit-any
183- function _eventFromIncompleteOnError ( msg : any , url : any , line : any , column : any ) : Event {
184- const ERROR_TYPES_RE =
185- / ^ (?: [ U u ] n c a u g h t (?: e x c e p t i o n : ) ? ) ? (?: ( (?: E v a l | I n t e r n a l | R a n g e | R e f e r e n c e | S y n t a x | T y p e | U R I | ) E r r o r ) : ) ? ( .* ) $ / i;
186-
187- // If 'message' is ErrorEvent, get real message from inside
188- let message = isErrorEvent ( msg ) ? msg . message : msg ;
189- let name = 'Error' ;
190-
191- const groups = message . match ( ERROR_TYPES_RE ) ;
192- if ( groups ) {
193- name = groups [ 1 ] ;
194- message = groups [ 2 ] ;
195- }
196-
197- const event = {
198- exception : {
199- values : [
200- {
201- type : name ,
202- value : message ,
203- } ,
204- ] ,
205- } ,
206- } ;
207-
208- return _enhanceEventWithInitialFrame ( event , url , line , column ) ;
209- }
210-
211153// eslint-disable-next-line @typescript-eslint/no-explicit-any
212154function _enhanceEventWithInitialFrame ( event : Event , url : any , line : any , column : any ) : Event {
213155 // event.exception
0 commit comments