(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
error: any,
{ componentStack }: ErrorInfo,
hint?: Parameters<typeof captureException>[1],
)
| 42 | * @returns the id of the captured Sentry event. |
| 43 | */ |
| 44 | export function captureReactException( |
| 45 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 46 | error: any, |
| 47 | { componentStack }: ErrorInfo, |
| 48 | hint?: Parameters<typeof captureException>[1], |
| 49 | ): string { |
| 50 | // If on React version >= 17, create stack trace from componentStack param and links |
| 51 | // to to the original error using `error.cause` otherwise relies on error param for stacktrace. |
| 52 | // Linking errors requires the `LinkedErrors` integration be enabled. |
| 53 | // See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks |
| 54 | // |
| 55 | // Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked |
| 56 | // with non-error objects. This is why we need to check if the error is an error-like object. |
| 57 | // See: https://github.com/getsentry/sentry-javascript/issues/6167 |
| 58 | if (isAtLeastReact17(version) && isError(error) && componentStack) { |
| 59 | const errorBoundaryError = new Error(error.message); |
| 60 | errorBoundaryError.name = `React ErrorBoundary ${error.name}`; |
| 61 | errorBoundaryError.stack = componentStack; |
| 62 | |
| 63 | // Using the `LinkedErrors` integration to link the errors together. |
| 64 | setCause(error, errorBoundaryError); |
| 65 | } |
| 66 | |
| 67 | return captureException(error, hint); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Creates an error handler that can be used with the `onCaughtError`, `onUncaughtError`, |
no test coverage detected