mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2025-07-27 17:00:06 +02:00

Upgrade react-error-boundary to version 5, second attempt GitOrigin-RevId: 2b88334b66f0ace383211c147279ff88e9f956bb
31 lines
853 B
TypeScript
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
|