MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / _validateBeforeSendResult

Function _validateBeforeSendResult

packages/core/src/client.ts:1620–1641  ·  view source on GitHub ↗

* Verifies that return value of configured `beforeSend` or `beforeSendTransaction` is of expected type, and returns the value if so.

(
  beforeSendResult: PromiseLike<Event | null> | Event | null,
  beforeSendLabel: string,
)

Source from the content-addressed store, hash-verified

1618 * Verifies that return value of configured `beforeSend` or `beforeSendTransaction` is of expected type, and returns the value if so.
1619 */
1620function _validateBeforeSendResult(
1621 beforeSendResult: PromiseLike<Event | null> | Event | null,
1622 beforeSendLabel: string,
1623): PromiseLike<Event | null> | Event | null {
1624 const invalidValueError = `${beforeSendLabel} must return \`null\` or a valid event.`;
1625 if (isThenable(beforeSendResult)) {
1626 return beforeSendResult.then(
1627 event => {
1628 if (!isPlainObject(event) && event !== null) {
1629 throw _makeInternalError(invalidValueError);
1630 }
1631 return event;
1632 },
1633 e => {
1634 throw _makeInternalError(`${beforeSendLabel} rejected with ${e}`);
1635 },
1636 );
1637 } else if (!isPlainObject(beforeSendResult) && beforeSendResult !== null) {
1638 throw _makeInternalError(invalidValueError);
1639 }
1640 return beforeSendResult;
1641}
1642
1643/**
1644 * Process the matching `beforeSendXXX` callback.

Callers 1

_processEventFunction · 0.85

Calls 4

isThenableFunction · 0.90
isPlainObjectFunction · 0.90
_makeInternalErrorFunction · 0.85
thenMethod · 0.45

Tested by

no test coverage detected