@@ -185,11 +185,18 @@ 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
+ 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
+ ) ;
193
200
} ) ;
194
201
return eventId ;
195
202
}
@@ -204,11 +211,19 @@ export class Hub implements HubInterface {
204
211
hint ?: EventHint ,
205
212
) : string {
206
213
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
+ ) ;
212
227
} ) ;
213
228
return eventId ;
214
229
}
@@ -222,9 +237,8 @@ export class Hub implements HubInterface {
222
237
this . _lastEventId = eventId ;
223
238
}
224
239
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 ) ;
228
242
} ) ;
229
243
return eventId ;
230
244
}
@@ -446,12 +460,10 @@ export class Hub implements HubInterface {
446
460
* @param method The method to call on the client.
447
461
* @param args Arguments to pass to the client function.
448
462
*/
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 {
451
464
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 ) ;
455
467
}
456
468
}
457
469
0 commit comments