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