File tree Expand file tree Collapse file tree 3 files changed +29
-45
lines changed Expand file tree Collapse file tree 3 files changed +29
-45
lines changed Original file line number Diff line number Diff line change 1
- import { CaptureContext , Hub } from '@sentry/types' ;
1
+ import { CaptureContext , Hub , Severity , SeverityLevel } from '@sentry/types' ;
2
2
3
3
import { getCurrentHub } from './hub' ;
4
4
@@ -27,3 +27,22 @@ export function callOnHub<T>(method: string, ...args: any[]): T {
27
27
export function captureException ( exception : any , captureContext ?: CaptureContext ) : string {
28
28
return getCurrentHub ( ) . captureException ( exception , { captureContext } ) ;
29
29
}
30
+
31
+ /**
32
+ * Captures a message event and sends it to Sentry.
33
+ *
34
+ * @param message The message to send to Sentry.
35
+ * @param Severity Define the level of the message.
36
+ * @returns The generated eventId.
37
+ */
38
+ export function captureMessage (
39
+ message : string ,
40
+ // eslint-disable-next-line deprecation/deprecation
41
+ captureContext ?: CaptureContext | Severity | SeverityLevel ,
42
+ ) : string {
43
+ // This is necessary to provide explicit scopes upgrade, without changing the original
44
+ // arity of the `captureMessage(message, level)` method.
45
+ const level = typeof captureContext === 'string' ? captureContext : undefined ;
46
+ const context = typeof captureContext !== 'string' ? { captureContext } : undefined ;
47
+ return getCurrentHub ( ) . captureMessage ( message , level , context ) ;
48
+ }
Original file line number Diff line number Diff line change @@ -211,27 +211,18 @@ export class Hub implements HubInterface {
211
211
hint ?: EventHint ,
212
212
) : string {
213
213
const eventId = ( this . _lastEventId = hint && hint . event_id ? hint . event_id : uuid4 ( ) ) ;
214
- let finalHint = hint ;
215
-
216
- // If there's no explicit hint provided, mimic the same thing that would happen
217
- // in the minimal itself to create a consistent behavior.
218
- // We don't do this in the client, as it's the lowest level API, and doing this,
219
- // would prevent user from having full control over direct calls.
220
- if ( ! hint ) {
221
- let syntheticException : Error ;
222
- try {
223
- throw new Error ( message ) ;
224
- } catch ( exception ) {
225
- syntheticException = exception as Error ;
226
- }
227
- finalHint = {
228
- originalException : message ,
229
- syntheticException,
230
- } ;
214
+
215
+ let syntheticException : Error ;
216
+ try {
217
+ throw new Error ( 'Sentry syntheticException' ) ;
218
+ } catch ( exception ) {
219
+ syntheticException = exception as Error ;
231
220
}
232
221
233
222
this . _invokeClient ( 'captureMessage' , message , level , {
234
- ...finalHint ,
223
+ originalException : message ,
224
+ syntheticException,
225
+ ...hint ,
235
226
event_id : eventId ,
236
227
} ) ;
237
228
return eventId ;
Original file line number Diff line number Diff line change @@ -29,32 +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 a message event and sends it to Sentry.
34
- *
35
- * @param message The message to send to Sentry.
36
- * @param Severity Define the level of the message.
37
- * @returns The generated eventId.
38
- */
39
- export function captureMessage (
40
- message : string ,
41
- // eslint-disable-next-line deprecation/deprecation
42
- captureContext ?: CaptureContext | Severity | SeverityLevel ,
43
- ) : string {
44
- const syntheticException = new Error ( message ) ;
45
-
46
- // This is necessary to provide explicit scopes upgrade, without changing the original
47
- // arity of the `captureMessage(message, level)` method.
48
- const level = typeof captureContext === 'string' ? captureContext : undefined ;
49
- const context = typeof captureContext !== 'string' ? { captureContext } : undefined ;
50
-
51
- return callOnHub ( 'captureMessage' , message , level , {
52
- originalException : message ,
53
- syntheticException,
54
- ...context ,
55
- } ) ;
56
- }
57
-
58
32
/**
59
33
* Captures a manually created event and sends it to Sentry.
60
34
*
You can’t perform that action at this time.
0 commit comments