overleaf-cep/services/web/frontend/js/infrastructure/error-boundary.tsx
Tim Down 5d78229e1e Merge pull request #25093 from overleaf/td-upgrade-react-error-boundary-second-attempt
Upgrade react-error-boundary to version 5, second attempt

GitOrigin-RevId: 2b88334b66f0ace383211c147279ff88e9f956bb
2025-04-29 08:06:23 +00:00

31 lines
853 B
TypeScript

import { captureException } from './error-reporter'
import { withErrorBoundary as rebWithErrorBoundary } from 'react-error-boundary'
import { ComponentType, ErrorInfo } from 'react'
import { FallbackProps } from 'react-error-boundary/dist/declarations/src/types'
function errorHandler(error: Error, errorInfo: ErrorInfo) {
captureException(error, {
extra: {
componentStack: errorInfo.componentStack,
},
tags: {
handler: 'react-error-boundary',
},
})
}
function DefaultFallbackComponent() {
return <></>
}
function withErrorBoundary(
WrappedComponent: ComponentType<any>,
FallbackComponent?: ComponentType<FallbackProps>
) {
return rebWithErrorBoundary(WrappedComponent, {
onError: errorHandler,
FallbackComponent: FallbackComponent || DefaultFallbackComponent,
})
}
export default withErrorBoundary