8000 clarify naming in `beforeSend` result validator and fix docstring · jonator/sentry-javascript@e3ac98b · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit e3ac98b

Browse files
committed
clarify naming in beforeSend result validator and fix docstring
1 parent d169df4 commit e3ac98b

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

packages/core/src/baseclient.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
646646
}
647647

648648
const beforeSendResult = beforeSend(prepared, hint);
649-
return _ensureBeforeSendRv(beforeSendResult);
649+
return _validateBeforeSendResult(beforeSendResult);
650650
})
651651
.then(processedEvent => {
652652
if (processedEvent === null) {
@@ -764,24 +764,26 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
764764
}
765765

766766
/**
767-
* Verifies that return value of configured `beforeSend` is of expected type.
767+
* Verifies that return value of configured `beforeSend` is of expected type, and returns the value if so.
768768
*/
769-
function _ensureBeforeSendRv(rv: PromiseLike<Event | null> | Event | null): PromiseLike<Event | null> | Event | null {
770-
const nullErr = '`beforeSend` must return `null` or a valid event.';
771-
if (isThenable(rv)) {
772-
return rv.then(
769+
function _validateBeforeSendResult(
770+
beforeSendResult: PromiseLike<Event | null> | Event | null,
771+
): PromiseLike<Event | null> | Event | null {
772+
const invalidValueError = '`beforeSend` must return `null` or a valid event.';
773+
if (isThenable(beforeSendResult)) {
774+
return beforeSendResult.then(
773775
event => {
774-
if (!(isPlainObject(event) || event === null)) {
775-
throw new SentryError(nullErr);
776+
if (!isPlainObject(event) && event !== null) {
777+
throw new SentryError(invalidValueError);
776778
}
777779
return event;
778780
},
779781
e => {
780782
throw new SentryError(`beforeSend rejected with ${e}`);
781783
},
782784
);
783-
} else if (!(isPlainObject(rv) || rv === null)) {
784-
throw new SentryError(nullErr);
785+
} else if (!isPlainObject(beforeSendResult) && beforeSendResult !== null) {
786+
throw new SentryError(invalidValueError);
785787
}
786-
return rv;
788+
return beforeSendResult;
787789
}

0 commit comments

Comments
 (0)
0