mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 16:32:23 -05:00
95352894a5
Add react-error-boundary to handle react errors in scope GitOrigin-RevId: 9bd8261057122fce08d8cea3b19b2c71e1d949f4
31 lines
857 B
JavaScript
31 lines
857 B
JavaScript
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' }
|
|
})
|
|
}
|
|
}
|
|
|
|
function withErrorBoundary(WrappedComponent, FallbackComponent) {
|
|
function ErrorBoundaryWrapper(props) {
|
|
return (
|
|
<ErrorBoundary
|
|
fallbackRender={FallbackComponent || null}
|
|
onError={errorHandler}
|
|
>
|
|
<WrappedComponent {...props} />
|
|
</ErrorBoundary>
|
|
)
|
|
}
|
|
ErrorBoundaryWrapper.propTypes = WrappedComponent.propTypes
|
|
ErrorBoundaryWrapper.displayName = `WithErrorBoundaryWrapper${WrappedComponent.displayName ||
|
|
WrappedComponent.name ||
|
|
'Component'}`
|
|
return ErrorBoundaryWrapper
|
|
}
|
|
|
|
export default withErrorBoundary
|