@@ -185,11 +185,18 @@ export class Hub implements HubInterface {
185185 // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
186186 public captureException ( exception : any , hint ?: EventHint ) : string {
187187 const eventId = ( this . _lastEventId = hint && hint . event_id ? hint . event_id : uuid4 ( ) ) ;
188- this . _invokeClient ( 'captureException' , exception , {
189- originalException : exception ,
190- syntheticException : new Error ( 'Sentry syntheticException' ) ,
191- ...hint ,
192- event_id : eventId ,
188+ const syntheticException = new Error ( 'Sentry syntheticException' ) ;
189+ this . _withClient ( ( client , scope ) => {
190+ client . captureException (
191+ exception ,
192+ {
193+ originalException : exception ,
194+ syntheticException,
195+ ...hint ,
196+ event_id : eventId ,
197+ } ,
198+ scope ,
199+ ) ;
193200 } ) ;
194201 return eventId ;
195202 }
@@ -204,11 +211,19 @@ export class Hub implements HubInterface {
204211 hint ?: EventHint ,
205212 ) : string {
206213 const eventId = ( this . _lastEventId = hint && hint . event_id ? hint . event_id : uuid4 ( ) ) ;
207- this . _invokeClient ( 'captureMessage' , message , level , {
208- originalException : message ,
209- syntheticException : new Error ( message ) ,
210- ...hint ,
211- event_id : eventId ,
214+ const syntheticException = new Error ( message ) ;
215+ this . _withClient ( ( client , scope ) => {
216+ client . captureMessage (
217+ message ,
218+ level ,
219+ {
220+ originalException : message ,
221+ syntheticException,
222+ ...hint ,
223+ event_id : eventId ,
224+ } ,
225+ scope ,
226+ ) ;
212227 } ) ;
213228 return eventId ;
214229 }
@@ -222,9 +237,8 @@ export class Hub implements HubInterface {
222237 this . _lastEventId = eventId ;
223238 }
224239
225- this . _invokeClient ( 'captureEvent' , event , {
226- ...hint ,
227- event_id : eventId ,
240+ this . _withClient ( ( client , scope ) => {
241+ client . captureEvent ( event , { ...hint , event_id : eventId } , scope ) ;
228242 } ) ;
229243 return eventId ;
230244 }
@@ -446,12 +460,10 @@ export class Hub implements HubInterface {
446460 * @param method The method to call on the client.
447461 * @param args Arguments to pass to the client function.
448462 */
449- // eslint-disable-next-line @typescript-eslint/no-explicit-any
450- private _invokeClient < M extends keyof Client > ( method : M , ...args : any [ ] ) : void {
463+ private _withClient ( callback : ( client : Client , scope : Scope | undefined ) => void ) : void {
451464 const { scope, client } = this . getStackTop ( ) ;
452- if ( client && client [ method ] ) {
453- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
454- ( client as any ) [ method ] ( ...args , scope ) ;
465+ if ( client ) {
466+ callback ( client , scope ) ;
455467 }
456468 }
457469
0 commit comments