@@ -255,7 +255,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
255255 * @param scope A scope containing event metadata.
256256 * @returns A new event with more information.
257257 */
258- protected _prepareEvent ( event : Event , scope ?: Scope , hint ?: EventHint ) : SyncPromise < Event | null > {
258+ protected _prepareEvent ( event : Event , scope ?: Scope , hint ?: EventHint ) : Promise < Event | null > {
259259 const { environment, release, dist, maxValueLength = 250 } = this . getOptions ( ) ;
260260
261261 const prepared : Event = { ...event } ;
@@ -327,7 +327,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
327327 * @param scope A scope containing event metadata.
328328 * @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.
329329 */
330- protected _processEvent ( event : Event , hint ?: EventHint , scope ?: Scope ) : SyncPromise < Event > {
330+ protected _processEvent ( event : Event , hint ?: EventHint , scope ?: Scope ) : Promise < Event > {
331331 const { beforeSend, sampleRate } = this . getOptions ( ) ;
332332
333333 if ( ! this . _isEnabled ( ) ) {
@@ -341,50 +341,54 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
341341 }
342342
343343 return new SyncPromise ( ( resolve , reject ) => {
344- this . _prepareEvent ( event , scope , hint ) . then ( prepared => {
345- if ( prepared === null ) {
346- reject ( 'An event processor returned null, will not send event.' ) ;
347- return ;
348- }
349-
350- let finalEvent : Event | null = prepared ;
351-
352- try {
353- const isInternalException = hint && hint . data && ( hint . data as { [ key : string ] : any } ) . __sentry__ === true ;
354- if ( isInternalException || ! beforeSend ) {
355- this . _getBackend ( ) . sendEvent ( finalEvent ) ;
356- resolve ( finalEvent ) ;
344+ this . _prepareEvent ( event , scope , hint )
345+ . then ( prepared => {
346+ if ( prepared === null ) {
347+ reject ( 'An event processor returned null, will not send event.' ) ;
357348 return ;
358349 }
359350
360- const beforeSendResult = beforeSend ( prepared , hint ) ;
361- if ( ( typeof beforeSendResult as any ) === 'undefined' ) {
362- logger . error ( '`beforeSend` method has to return `null` or a valid event.' ) ;
363- } else if ( isThenable ( beforeSendResult ) ) {
364- this . _handleAsyncBeforeSend ( beforeSendResult as Promise < Event | null > , resolve , reject ) ;
365- } else {
366- finalEvent = beforeSendResult as Event | null ;
367-
368- if ( finalEvent === null ) {
369- logger . log ( '`beforeSend` returned `null`, will not send event.' ) ;
370- resolve ( null ) ;
351+ let finalEvent : Event | null = prepared ;
352+
353+ try {
354+ const isInternalException = hint && hint . data && ( hint . data as { [ key : string ] : any } ) . __sentry__ === true ;
355+ if ( isInternalException || ! beforeSend ) {
356+ this . _getBackend ( ) . sendEvent ( finalEvent ) ;
357+ resolve ( finalEvent ) ;
371358 return ;
372359 }
373360
374- // From here on we are really async
375- this . _getBackend ( ) . sendEvent ( finalEvent ) ;
376- resolve ( finalEvent ) ;
361+ const beforeSendResult = beforeSend ( prepared , hint ) ;
362+ if ( ( typeof beforeSendResult as any ) === 'undefined' ) {
363+ logger . error ( '`beforeSend` method has to return `null` or a valid event.' ) ;
364+ } else if ( isThenable ( beforeSendResult ) ) {
365+ this . _handleAsyncBeforeSend ( beforeSendResult as Promise < Event | null > , resolve , reject ) ;
366+ } else {
367+ finalEvent = beforeSendResult as Event | null ;
368+
369+ if ( finalEvent === null ) {
370+ logger . log ( '`beforeSend` returned `null`, will not send event.' ) ;
371+ resolve ( null ) ;
372+ return ;
373+ }
374+
375+ // From here on we are really async
376+ this . _getBackend ( ) . sendEvent ( finalEvent ) ;
377+ resolve ( finalEvent ) ;
378+ }
379+ } catch ( exception ) {
380+ this . captureException ( exception , {
381+ data : {
382+ __sentry__ : true ,
383+ } ,
384+ originalException : exception as Error ,
385+ } ) ;
386+ reject ( '`beforeSend` threw an error, will not send event.' ) ;
377387 }
378- } catch ( exception ) {
379- this . captureException ( exception , {
380- data : {
381- __sentry__ : true ,
382- } ,
383- originalException : exception as Error ,
384- } ) ;
385- reject ( '`beforeSend` throw an error, will not send event.' ) ;
386- }
387- } ) ;
388+ } )
389+ . catch ( ( ) => {
390+ reject ( '`beforeSend` threw an error, will not send event.' ) ;
391+ } ) ;
388392 } ) ;
389393 }
390394
0 commit comments