1
- import { Event } from '@sentry/types' ;
1
+ import { Event , EventHint , Options , Severity } from '@sentry/types' ;
2
2
import {
3
3
addExceptionMechanism ,
4
4
addExceptionTypeValue ,
@@ -8,12 +8,56 @@ import {
8
8
isErrorEvent ,
9
9
isEvent ,
10
10
isPlainObject ,
11
+ SyncPromise ,
11
12
} from '@sentry/utils' ;
12
13
13
14
import { eventFromPlainObject , eventFromStacktrace , prepareFramesForEvent } from './parsers' ;
14
15
import { computeStackTrace } from './tracekit' ;
15
16
16
- /** JSDoc */
17
+ /**
18
+ * Builds and Event from a Exception
19
+ * @hidden
20
+ */
21
+ export function eventFromException ( options : Options , exception : any , hint ?: EventHint ) : PromiseLike < Event > {
22
+ const syntheticException = ( hint && hint . syntheticException ) || undefined ;
23
+ const event = eventFromUnknownInput ( exception , syntheticException , {
24
+ attachStacktrace : options . attachStacktrace ,
25
+ } ) ;
26
+ addExceptionMechanism ( event , {
27
+ handled : true ,
28
+ type : 'generic' ,
29
+ } ) ;
30
+ event . level = Severity . Error ;
31
+ if ( hint && hint . event_id ) {
32
+ event . event_id = hint . event_id ;
33
+ }
34
+ return SyncPromise . resolve ( event ) ;
35
+ }
36
+
37
+ /**
38
+ * Builds and Event from a Message
39
+ * @hidden
40
+ */
41
+ export function eventFromMessage (
42
+ options : Options ,
43
+ message : string ,
44
+ level : Severity = Severity . Info ,
45
+ hint ?: EventHint ,
46
+ ) : PromiseLike < Event > {
47
+ const syntheticException = ( hint && hint . syntheticException ) || undefined ;
48
+ const event = eventFromString ( message , syntheticException , {
49
+ attachStacktrace : options . attachStacktrace ,
50
+ } ) ;
51
+ event . level = level ;
52
+ if ( hint && hint . event_id ) {
53
+ event . event_id = hint . event_id ;
54
+ }
55
+ return SyncPromise . resolve ( event ) ;
56
+ }
57
+
58
+ /**
59
+ * @hidden
60
+ */
17
61
export function eventFromUnknownInput (
18
62
exception : unknown ,
19
63
syntheticException ?: Error ,
@@ -79,8 +123,9 @@ export function eventFromUnknownInput(
79
123
return event ;
80
124
}
81
125
82
- // this._options.attachStacktrace
83
- /** JSDoc */
126
+ /**
127
+ * @hidden
128
+ */
84
129
export function eventFromString (
85
130
input : string ,
86
131
syntheticException ?: Error ,
0 commit comments