|
1 | | -import { |
2 | | - captureEvent, |
3 | | - captureException, |
4 | | - eventFromException, |
5 | | - ReportDialogOptions, |
6 | | - Scope, |
7 | | - showReportDialog, |
8 | | - withScope, |
9 | | -} from '@sentry/browser'; |
10 | | -import { Event } from '@sentry/types'; |
| 1 | +import { captureException, ReportDialogOptions, Scope, showReportDialog, withScope } from '@sentry/browser'; |
11 | 2 | import { logger, parseSemver } from '@sentry/utils'; |
12 | 3 | import hoistNonReactStatics from 'hoist-non-react-statics'; |
13 | 4 | import * as React from 'react'; |
@@ -71,31 +62,14 @@ const INITIAL_STATE = { |
71 | 62 | * @param error An error captured by React Error Boundary |
72 | 63 | * @param componentStack The component stacktrace |
73 | 64 | */ |
74 | | -function captureReactErrorBoundaryError(error: Error, componentStack: string): string { |
75 | | - const errorBoundaryError = new Error(error.message); |
76 | | - errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`; |
77 | | - errorBoundaryError.stack = componentStack; |
78 | | - |
79 | | - let errorBoundaryEvent: Event = {}; |
80 | | - void eventFromException({}, errorBoundaryError).then(e => { |
81 | | - errorBoundaryEvent = e; |
82 | | - }); |
83 | | - |
84 | | - if ( |
85 | | - errorBoundaryEvent.exception && |
86 | | - Array.isArray(errorBoundaryEvent.exception.values) && |
87 | | - reactVersion.major && |
88 | | - reactVersion.major >= 17 |
89 | | - ) { |
90 | | - let originalEvent: Event = {}; |
91 | | - void eventFromException({}, error).then(e => { |
92 | | - originalEvent = e; |
93 | | - }); |
94 | | - if (originalEvent.exception && Array.isArray(originalEvent.exception.values)) { |
95 | | - originalEvent.exception.values = [...errorBoundaryEvent.exception.values, ...originalEvent.exception.values]; |
96 | | - } |
97 | | - |
98 | | - return captureEvent(originalEvent); |
| 65 | +function captureReactErrorBoundaryError(error: Error & { cause?: Error }, componentStack: string): string { |
| 66 | + if (reactVersion.major && reactVersion.major >= 17) { |
| 67 | + const errorBoundaryError = new Error(error.message); |
| 68 | + errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`; |
| 69 | + errorBoundaryError.stack = componentStack; |
| 70 | + |
| 71 | + error.cause = errorBoundaryError; |
| 72 | + return captureException(error); |
99 | 73 | } |
100 | 74 |
|
101 | 75 | return captureException(error, { contexts: { react: { componentStack } } }); |
|
0 commit comments