overleaf/services/web/frontend/js/infrastructure/error-boundary.js
Alf Eaton 1ebc8a79cb Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2

GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
2021-04-15 02:05:22 +00:00

35 lines
1,000 B
JavaScript

import React from 'react'
import { captureException } from './error-reporter'
import { ErrorBoundary } from 'react-error-boundary'
function errorHandler(error, componentStack) {
captureException(error, scope => {
scope.setExtra('componentStack', componentStack)
scope.setTag('handler', 'react-error-boundary')
return scope
})
}
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