@@ -185,11 +185,17 @@ export class Hub implements HubInterface {
185
185
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
186
186
public captureException ( exception : any , hint ?: EventHint ) : string {
187
187
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
+ ) ;
193
199
} ) ;
194
200
return eventId ;
195
201
}
@@ -204,11 +210,18 @@ export class Hub implements HubInterface {
204
210
hint ?: EventHint ,
205
211
) : string {
206
212
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 ( 'Sentry syntheticException' ) ,
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 ( 'Sentry syntheticException' ) ,
220
+ ...hint ,
221
+ event_id : eventId ,
222
+ } ,
223
+ scope ,
224
+ ) ;
212
225
} ) ;
213
226
return eventId ;
214
227
}
@@ -222,9 +235,8 @@ export class Hub implements HubInterface {
222
235
this . _lastEventId = eventId ;
223
236
}
224
237
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 ) ;
228
240
} ) ;
229
241
return eventId ;
230
242
}
@@ -447,11 +459,10 @@ export class Hub implements HubInterface {
447
459
* @param args Arguments to pass to the client function.
448
460
*/
449
461
// 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 {
451
463
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 ) ;
455
466
}
456
467
}
457
468
0 commit comments