1- import { BaseBackend , getCurrentHub } from '@sentry/core' ;
2- import { Event , EventHint , Mechanism , SeverityLevel , Transport , TransportOptions } from '@sentry/types' ;
3- import {
4- addExceptionMechanism ,
5- addExceptionTypeValue ,
6- Dsn ,
7- extractExceptionKeysForMessage ,
8- isError ,
9- isPlainObject ,
10- normalizeToSize ,
11- SyncPromise ,
12- } from '@sentry/utils' ;
1+ import { BaseBackend } from '@sentry/core' ;
2+ import { Event , EventHint , SeverityLevel , Transport , TransportOptions } from '@sentry/types' ;
3+ import { Dsn } from '@sentry/utils' ;
134
14- import { extractStackFromError , parseError , parseStack , prepareFramesForEvent } from './parsers ' ;
5+ import { eventFromException , eventFromMessage } from './eventbuilder ' ;
156import { HTTPSTransport , HTTPTransport } from './transports' ;
167import { NodeOptions } from './types' ;
178
@@ -25,78 +16,14 @@ export class NodeBackend extends BaseBackend<NodeOptions> {
2516 */
2617 // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
2718 public eventFromException ( exception : any , hint ?: EventHint ) : PromiseLike < Event > {
28- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29- let ex : any = exception ;
30- const providedMechanism : Mechanism | undefined =
31- hint && hint . data && ( hint . data as { mechanism : Mechanism } ) . mechanism ;
32- const mechanism : Mechanism = providedMechanism || {
33- handled : true ,
34- type : 'generic' ,
35- } ;
36-
37- if ( ! isError ( exception ) ) {
38- if ( isPlainObject ( exception ) ) {
39- // This will allow us to group events based on top-level keys
40- // which is much better than creating new group when any key/value change
41- const message = `Non-Error exception captured with keys: ${ extractExceptionKeysForMessage ( exception ) } ` ;
42-
43- getCurrentHub ( ) . configureScope ( scope => {
44- scope . setExtra ( '__serialized__' , normalizeToSize ( exception as Record < string , unknown > ) ) ;
45- } ) ;
46-
47- ex = ( hint && hint . syntheticException ) || new Error ( message ) ;
48- ( ex as Error ) . message = message ;
49- } else {
50- // This handles when someone does: `throw "something awesome";`
51- // We use synthesized Error here so we can extract a (rough) stack trace.
52- ex = ( hint && hint . syntheticException ) || new Error ( exception as string ) ;
53- ( ex as Error ) . message = exception ;
54- }
55- mechanism . synthetic = true ;
56- }
57-
58- return new SyncPromise < Event > ( ( resolve , reject ) =>
59- parseError ( ex as Error , this . _options )
60- . then ( event => {
61- addExceptionTypeValue ( event , undefined , undefined ) ;
62- addExceptionMechanism ( event , mechanism ) ;
63-
64- resolve ( {
65- ...event ,
66- event_id : hint && hint . event_id ,
67- } ) ;
68- } )
69- . then ( null , reject ) ,
70- ) ;
19+ return eventFromException ( this . _options , exception , hint ) ;
7120 }
7221
7322 /**
7423 * @inheritDoc
7524 */
7625 public eventFromMessage ( message : string , level : SeverityLevel = 'info' , hint ?: EventHint ) : PromiseLike < Event > {
77- const event : Event = {
78- event_id : hint && hint . event_id ,
79- level,
80- message,
81- } ;
82-
83- return new SyncPromise < Event > ( resolve => {
84- if ( this . _options . attachStacktrace && hint && hint . syntheticException ) {
85- const stack = hint . syntheticException ? extractStackFromError ( hint . syntheticException ) : [ ] ;
86- void parseStack ( stack , this . _options )
87- . then ( frames => {
88- event . stacktrace = {
89- frames : prepareFramesForEvent ( frames ) ,
90- } ;
91- resolve ( event ) ;
92- } )
93- . then ( null , ( ) => {
94- resolve ( event ) ;
95- } ) ;
96- } else {
97- resolve ( event ) ;
98- }
99- } ) ;
26+ return eventFromMessage ( this . _options , message , level , hint ) ;
10027 }
10128
10229 /**
0 commit comments