overleaf/services/web/frontend/js/infrastructure/error-boundary.js
Jakob Ackermann b795579ca0 Merge pull request #9006 from overleaf/jpa-sentry-error-context
[web] send OError info and OError tags/cause tracebacks to sentry

GitOrigin-RevId: 0544768ca16fcafb63ec6116a573e83302cdbdd3
2022-07-29 08:04:35 +00:00

37 lines
943 B
JavaScript

import { captureException } from './error-reporter'
import { ErrorBoundary } from 'react-error-boundary'
function errorHandler(error, componentStack) {
captureException(error, {
extra: {
componentStack,
},
tags: {
handler: 'react-error-boundary',
},
})
}
function DefaultFallbackComponent() {
return <></>
}
function withErrorBoundary(WrappedComponent, FallbackComponent) {
function ErrorBoundaryWrapper(props) {
return (
<ErrorBoundary
FallbackComponent={FallbackComponent || DefaultFallbackComponent}
onError={errorHandler}
>
<WrappedComponent {...props} />
</ErrorBoundary>
)
}
ErrorBoundaryWrapper.propTypes = WrappedComponent.propTypes
ErrorBoundaryWrapper.displayName = `WithErrorBoundaryWrapper${
WrappedComponent.displayName || WrappedComponent.name || 'Component'
}`
return ErrorBoundaryWrapper
}
export default withErrorBoundary