Skip to content

Commit a0a8734

Browse files
committed
ref(core): Streamline before send labels
1 parent bad6070 commit a0a8734

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/core/src/baseclient.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
632632
const isTransaction = event.type === 'transaction';
633633
const isError = !event.type;
634634
const eventType = event.type || 'error';
635+
const beforeSendLabel = `before send for type \`${eventType}\``;
635636

636637
// 1.0 === 100% events are sent
637638
// 0.0 === 0% events are sent
@@ -659,12 +660,12 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
659660
}
660661

661662
const result = processBeforeSend(options, prepared, hint);
662-
return _validateBeforeSendResult(result, eventType);
663+
return _validateBeforeSendResult(result, beforeSendLabel);
663664
})
664665
.then(processedEvent => {
665666
if (processedEvent === null) {
666667
this.recordDroppedEvent('before_send', event.type || 'error', event);
667-
throw new SentryError(`before send for type \`${eventType}\` returned \`null\`, will not send event.`, 'log');
668+
throw new SentryError(`${beforeSendLabel} returned \`null\`, will not send event.`, 'log');
668669
}
669670

670671
const session = scope && scope.getSession();
@@ -781,9 +782,9 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
781782
*/
782783
function _validateBeforeSendResult(
783784
beforeSendResult: PromiseLike<Event | null> | Event | null,
784-
eventType: string,
785+
beforeSendLabel: string,
785786
): PromiseLike<Event | null> | Event | null {
786-
const invalidValueError = `before send for type \`${eventType}\` must return \`null\` or a valid event.`;
787+
const invalidValueError = `${beforeSendLabel} must return \`null\` or a valid event.`;
787788
if (isThenable(beforeSendResult)) {
788789
return beforeSendResult.then(
789790
event => {
@@ -793,7 +794,7 @@ function _validateBeforeSendResult(
793794
return event;
794795
},
795796
e => {
796-
throw new SentryError(`before send for type \`${eventType}\` rejected with ${e}`);
797+
throw new SentryError(`${beforeSendLabel} rejected with ${e}`);
797798
},
798799
);
799800
} else if (!isPlainObject(beforeSendResult) && beforeSendResult !== null) {

0 commit comments

Comments
 (0)