File tree Expand file tree Collapse file tree 3 files changed +37
-35
lines changed Expand file tree Collapse file tree 3 files changed +37
-35
lines changed Original file line number Diff line number Diff line change
1
+ import { CaptureContext , Hub } from '@sentry/types' ;
2
+
3
+ import { getCurrentHub } from './hub' ;
4
+
5
+ /**
6
+ * This calls a function on the current hub.
7
+ * @param method function to call on hub.
8
+ * @param args to pass to function.
9
+ */
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ export function callOnHub < T > ( method : string , ...args : any [ ] ) : T {
12
+ const hub = getCurrentHub ( ) ;
13
+ if ( hub && hub [ method as keyof Hub ] ) {
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ return ( hub [ method as keyof Hub ] as any ) ( ...args ) ;
16
+ }
17
+ throw new Error ( `No hub defined or ${ method } was not found on the hub, please open a bug report.` ) ;
18
+ }
19
+
20
+ /**
21
+ * Captures an exception event and sends it to Sentry.
22
+ *
23
+ * @param exception An exception-like object.
24
+ * @returns The generated eventId.
25
+ */
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
27
+ export function captureException ( exception : any , captureContext ?: CaptureContext ) : string {
28
+ return getCurrentHub ( ) . captureException ( exception , { captureContext } ) ;
29
+ }
Original file line number Diff line number Diff line change @@ -185,27 +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
- let finalHint = hint ;
189
188
190
- // If there's no explicit hint provided, mimic the same thing that would happen
191
- // in the minimal itself to create a consistent behavior.
192
- // We don't do this in the client, as it's the lowest level API, and doing this,
193
- // would prevent user from having full control over direct calls.
194
- if ( ! hint ) {
195
- let syntheticException : Error ;
196
- try {
197
- throw new Error ( 'Sentry syntheticException' ) ;
198
- } catch ( exception ) {
199
- syntheticException = exception as Error ;
200
- }
201
- finalHint = {
202
- originalException : exception ,
203
- syntheticException,
204
- } ;
189
+ let syntheticException : Error ;
190
+ try {
191
+ throw new Error ( 'Sentry syntheticException' ) ;
192
+ } catch ( exception ) {
193
+ syntheticException = exception as Error ;
205
194
}
206
-
207
195
this . _invokeClient ( 'captureException' , exception , {
208
- ...finalHint ,
196
+ originalException : exception ,
197
+ syntheticException,
198
+ ...hint ,
209
199
event_id : eventId ,
210
200
} ) ;
211
201
return eventId ;
Original file line number Diff line number Diff line change @@ -29,23 +29,6 @@ function callOnHub<T>(method: string, ...args: any[]): T {
29
29
throw new Error ( `No hub defined or ${ method } was not found on the hub, please open a bug report.` ) ;
30
30
}
31
31
32
- /**
33
- * Captures an exception event and sends it to Sentry.
34
- *
35
- * @param exception An exception-like object.
36
- * @returns The generated eventId.
37
- */
38
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
39
- export function captureException ( exception : any , captureContext ?: CaptureContext ) : string {
40
- const syntheticException = new Error ( 'Sentry syntheticException' ) ;
41
-
42
- return callOnHub ( 'captureException' , exception , {
43
- captureContext,
44
- originalException : exception ,
45
- syntheticException,
46
- } ) ;
47
- }
48
-
49
32
/**
50
33
* Captures a message event and sends it to Sentry.
51
34
*
You can’t perform that action at this time.
0 commit comments