Files
overleaf-cep/services/web/frontend/js/infrastructure/error-boundary.tsx
T
Alf Eaton ce4ca192ee Upgrade Storybook to v10 (#30442)
GitOrigin-RevId: 9f51624bc2b34b6746d1854969173b44c9c9cf9a
2026-04-22 08:06:26 +00:00

34 lines
792 B
TypeScript

import { captureException } from './error-reporter'
import {
withErrorBoundary as rebWithErrorBoundary,
FallbackProps,
} from 'react-error-boundary'
import { ComponentType, ErrorInfo } from 'react'
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