2020-12-03 13:58:46 +00:00
|
|
|
import { captureException } from './error-reporter'
|
2020-09-16 08:53:29 +00:00
|
|
|
import { ErrorBoundary } from 'react-error-boundary'
|
|
|
|
|
|
|
|
function errorHandler(error, componentStack) {
|
2022-07-28 14:38:55 +00:00
|
|
|
captureException(error, {
|
|
|
|
extra: {
|
|
|
|
componentStack,
|
|
|
|
},
|
|
|
|
tags: {
|
|
|
|
handler: 'react-error-boundary',
|
|
|
|
},
|
2020-12-03 13:58:46 +00:00
|
|
|
})
|
2020-09-16 08:53:29 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 10:02:34 +00:00
|
|
|
function DefaultFallbackComponent() {
|
|
|
|
return <></>
|
|
|
|
}
|
|
|
|
|
2020-09-16 08:53:29 +00:00
|
|
|
function withErrorBoundary(WrappedComponent, FallbackComponent) {
|
|
|
|
function ErrorBoundaryWrapper(props) {
|
|
|
|
return (
|
|
|
|
<ErrorBoundary
|
2020-09-18 10:02:34 +00:00
|
|
|
FallbackComponent={FallbackComponent || DefaultFallbackComponent}
|
2020-09-16 08:53:29 +00:00
|
|
|
onError={errorHandler}
|
|
|
|
>
|
|
|
|
<WrappedComponent {...props} />
|
|
|
|
</ErrorBoundary>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
ErrorBoundaryWrapper.propTypes = WrappedComponent.propTypes
|
2021-04-14 13:17:21 +00:00
|
|
|
ErrorBoundaryWrapper.displayName = `WithErrorBoundaryWrapper${
|
|
|
|
WrappedComponent.displayName || WrappedComponent.name || 'Component'
|
|
|
|
}`
|
2020-09-16 08:53:29 +00:00
|
|
|
return ErrorBoundaryWrapper
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withErrorBoundary
|