@@ -185,11 +185,17 @@ 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+ this . _withClient ( ( client , scope ) => {
189+ client . captureException (
190+ exception ,
191+ {
192+ originalException : exception ,
193+ syntheticException : new Error ( 'Sentry syntheticException' ) ,
194+ ...hint ,
195+ event_id : eventId ,
196+ } ,
197+ scope ,
198+ ) ;
193199 } ) ;
194200 return eventId ;
195201 }
@@ -204,11 +210,18 @@ export class Hub implements HubInterface {
204210 hint ?: EventHint ,
205211 ) : string {
206212 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 ,
213+ this . _withClient ( ( client , scope ) => {
214+ client . captureMessage (
215+ message ,
216+ level ,
217+ {
218+ originalException : message ,
219+ syntheticException : new Error ( message ) ,
220+ ...hint ,
221+ event_id : eventId ,
222+ } ,
223+ scope ,
224+ ) ;
212225 } ) ;
213226 return eventId ;
214227 }
@@ -222,9 +235,8 @@ export class Hub implements HubInterface {
222235 this . _lastEventId = eventId ;
223236 }
224237
225- this . _invokeClient ( 'captureEvent' , event , {
226- ...hint ,
227- event_id : eventId ,
238+ this . _withClient ( ( client , scope ) => {
239+ client . captureEvent ( event , { ...hint , event_id : eventId } , scope ) ;
228240 } ) ;
229241 return eventId ;
230242 }
@@ -447,11 +459,10 @@ export class Hub implements HubInterface {
447459 * @param args Arguments to pass to the client function.
448460 */
449461 // eslint-disable-next-line @typescript-eslint/no-explicit-any
450- private _invokeClient < M extends keyof Client > ( method : M , ... args : any [ ] ) : void {
462+ private _withClient ( callback : ( client : Client , scope : Scope | undefined ) => void ) : void {
451463 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 ) ;
464+ if ( client ) {
465+ callback ( client , scope ) ;
455466 }
456467 }
457468
0 commit comments