Skip to content

Commit a46f7ee

Browse files
authored
ref: Notify user when event failed to deliver because of digestion pipeline issue (getsentry#2416)
1 parent be2fd1b commit a46f7ee

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

packages/core/src/baseclient.ts

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -394,45 +394,43 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
394394

395395
let finalEvent: Event | null = prepared;
396396

397-
try {
398-
const isInternalException = hint && hint.data && (hint.data as { [key: string]: any }).__sentry__ === true;
399-
if (isInternalException || !beforeSend) {
400-
this._getBackend().sendEvent(finalEvent);
401-
resolve(finalEvent);
397+
const isInternalException = hint && hint.data && (hint.data as { [key: string]: any }).__sentry__ === true;
398+
if (isInternalException || !beforeSend) {
399+
this._getBackend().sendEvent(finalEvent);
400+
resolve(finalEvent);
401+
return;
402+
}
403+
404+
const beforeSendResult = beforeSend(prepared, hint);
405+
// tslint:disable-next-line:strict-type-predicates
406+
if (typeof beforeSendResult === 'undefined') {
407+
logger.error('`beforeSend` method has to return `null` or a valid event.');
408+
} else if (isThenable(beforeSendResult)) {
409+
this._handleAsyncBeforeSend(beforeSendResult as PromiseLike<Event | null>, resolve, reject);
410+
} else {
411+
finalEvent = beforeSendResult as Event | null;
412+
413+
if (finalEvent === null) {
414+
logger.log('`beforeSend` returned `null`, will not send event.');
415+
resolve(null);
402416
return;
403417
}
404418

405-
const beforeSendResult = beforeSend(prepared, hint);
406-
// tslint:disable-next-line:strict-type-predicates
407-
if (typeof beforeSendResult === 'undefined') {
408-
logger.error('`beforeSend` method has to return `null` or a valid event.');
409-
} else if (isThenable(beforeSendResult)) {
410-
this._handleAsyncBeforeSend(beforeSendResult as PromiseLike<Event | null>, resolve, reject);
411-
} else {
412-
finalEvent = beforeSendResult as Event | null;
413-
414-
if (finalEvent === null) {
415-
logger.log('`beforeSend` returned `null`, will not send event.');
416-
resolve(null);
417-
return;
418-
}
419-
420-
// From here on we are really async
421-
this._getBackend().sendEvent(finalEvent);
422-
resolve(finalEvent);
423-
}
424-
} catch (exception) {
425-
this.captureException(exception, {
426-
data: {
427-
__sentry__: true,
428-
},
429-
originalException: exception as Error,
430-
});
431-
reject('`beforeSend` threw an error, will not send event.');
419+
// From here on we are really async
420+
this._getBackend().sendEvent(finalEvent);
421+
resolve(finalEvent);
432422
}
433423
})
434-
.then(null, () => {
435-
reject('`beforeSend` threw an error, will not send event.');
424+
.then(null, reason => {
425+
this.captureException(reason, {
426+
data: {
427+
__sentry__: true,
428+
},
429+
originalException: reason as Error,
430+
});
431+
reject(
432+
`Event processing pipeline threw an error, original event will not be sent. Details has been sent as a new event.\nReason: ${reason}`,
433+
);
436434
});
437435
});
438436
}

0 commit comments

Comments
 (0)