2020-09-16 04:53:29 -04:00
|
|
|
import React from 'react'
|
|
|
|
import { ErrorBoundary } from 'react-error-boundary'
|
|
|
|
|
|
|
|
function errorHandler(error, componentStack) {
|
|
|
|
if (window.Raven) {
|
|
|
|
Raven.captureException(error, {
|
|
|
|
extra: { componentStack },
|
|
|
|
tags: { mechanism: 'react-error-boundary' }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
ErrorBoundaryWrapper.displayName = `WithErrorBoundaryWrapper${WrappedComponent.displayName ||
|
|
|
|
WrappedComponent.name ||
|
|
|
|
'Component'}`
|
|
|
|
return ErrorBoundaryWrapper
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withErrorBoundary
|