diff --git a/CHANGELOG.md b/CHANGELOG.md index 78f5ae2033d9..c48ee05b6c29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott - [react] feat: Export `createReduxEnhancer` to log redux actions as breadcrumbs, and attach state as an extra. (#2717) - [tracing] feat: `Add @sentry/tracing` (#2719) -- [react] feat: Add `beforeSend` option to ErrorBoundary +- [react] feat: Add `beforeCapture` option to ErrorBoundary (#2753) ## 5.19.2 diff --git a/packages/react/src/errorboundary.tsx b/packages/react/src/errorboundary.tsx index c1995aa4c59d..0398e05e6bd2 100644 --- a/packages/react/src/errorboundary.tsx +++ b/packages/react/src/errorboundary.tsx @@ -39,7 +39,7 @@ export type ErrorBoundaryProps = { /** Called on componentWillUnmount() */ onUnmount?(error: Error | null, componentStack: string | null, eventId: string | null): void; /** Called before error is sent to Sentry, allows for you to add tags or context using the scope */ - beforeSend?(scope: Scope, error: Error | null, componentStack: string | null): void; + beforeCapture?(scope: Scope, error: Error | null, componentStack: string | null): void; }; type ErrorBoundaryState = { @@ -62,11 +62,11 @@ class ErrorBoundary extends React.Component { - if (beforeSend) { - beforeSend(scope, error, componentStack); + if (beforeCapture) { + beforeCapture(scope, error, componentStack); } const eventId = captureException(error, { contexts: { react: { componentStack } } }); if (onError) { diff --git a/packages/react/test/errorboundary.test.tsx b/packages/react/test/errorboundary.test.tsx index 62cfd716fe6c..fe427d0e53ac 100644 --- a/packages/react/test/errorboundary.test.tsx +++ b/packages/react/test/errorboundary.test.tsx @@ -202,28 +202,28 @@ describe('ErrorBoundary', () => { }); }); - it('calls `beforeSend()` when an error occurs', () => { - const mockBeforeSend = jest.fn(); + it('calls `beforeCapture()` when an error occurs', () => { + const mockBeforeCapture = jest.fn(); - const testBeforeSend = (...args: any[]) => { + const testBeforeCapture = (...args: any[]) => { expect(mockCaptureException).toHaveBeenCalledTimes(0); - mockBeforeSend(...args); + mockBeforeCapture(...args); }; render( - You have hit an error

} beforeSend={testBeforeSend}> + You have hit an error

} beforeCapture={testBeforeCapture}>

children

, ); - expect(mockBeforeSend).toHaveBeenCalledTimes(0); + expect(mockBeforeCapture).toHaveBeenCalledTimes(0); expect(mockCaptureException).toHaveBeenCalledTimes(0); const btn = screen.getByTestId('errorBtn'); fireEvent.click(btn); - expect(mockBeforeSend).toHaveBeenCalledTimes(1); - expect(mockBeforeSend).toHaveBeenLastCalledWith(expect.any(Scope), expect.any(Error), expect.any(String)); + expect(mockBeforeCapture).toHaveBeenCalledTimes(1); + expect(mockBeforeCapture).toHaveBeenLastCalledWith(expect.any(Scope), expect.any(Error), expect.any(String)); expect(mockCaptureException).toHaveBeenCalledTimes(1); });