|
|
|
@ -1,8 +1,8 @@ |
|
|
|
import React from 'react' |
|
|
|
// eslint-disable react/destructuring-assignment
|
|
|
|
|
|
|
|
|
|
|
|
import type{ ReactNode } from 'react' |
|
|
|
import { Component } from 'react' |
|
|
|
|
|
|
|
|
|
|
|
import * as Sentry from '@sentry/react' |
|
|
|
import type{ ErrorInfo, ReactNode } from 'react' |
|
|
|
|
|
|
|
|
|
|
|
import { Error } from '../Error' |
|
|
|
import { Error } from '../Error' |
|
|
|
|
|
|
|
|
|
|
|
@ -10,15 +10,41 @@ interface Props { |
|
|
|
children?: ReactNode, |
|
|
|
children?: ReactNode, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const ErrorBoundary = ({ children }: Props) => ( |
|
|
|
interface State { |
|
|
|
<Sentry.ErrorBoundary fallback={( |
|
|
|
hasError: boolean, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ErrorBoundary extends Component<Props, State> { |
|
|
|
|
|
|
|
// eslint-disable-next-line react/state-in-constructor
|
|
|
|
|
|
|
|
public state: State = { |
|
|
|
|
|
|
|
hasError: false, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static getDerivedStateFromError(_: Error): State { |
|
|
|
|
|
|
|
// Update state so the next render will show the fallback UI.
|
|
|
|
|
|
|
|
return { hasError: true } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public componentDidCatch(error: Error, errorInfo: ErrorInfo) { |
|
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
|
|
|
|
console.error( |
|
|
|
|
|
|
|
'Uncaught error:', |
|
|
|
|
|
|
|
error, |
|
|
|
|
|
|
|
errorInfo, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public render() { |
|
|
|
|
|
|
|
const { hasError } = this.state |
|
|
|
|
|
|
|
const { children } = this.props |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
<> |
|
|
|
<> |
|
|
|
|
|
|
|
{hasError && <Error />} |
|
|
|
{children} |
|
|
|
{children} |
|
|
|
<Error /> |
|
|
|
|
|
|
|
</> |
|
|
|
</> |
|
|
|
)} |
|
|
|
) |
|
|
|
> |
|
|
|
} |
|
|
|
{ children } |
|
|
|
} |
|
|
|
</Sentry.ErrorBoundary> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default ErrorBoundary |
|
|
|
|