Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import { Component, ErrorInfo, ReactNode } from 'react'
import { getLogger } from '../logging/log-util'
import ErrorPage from './ErrorPage'
interface ErrorBoundaryProps {
children?: ReactNode
}
interface ErrorBoundaryState {
hasError: boolean
}
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
public state: ErrorBoundaryState = {
hasError: false,
}
public static getDerivedStateFromError(): ErrorBoundaryState {
// Update state so the next render will show the fallback UI.
return { hasError: true }
}
public componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
// Log the error to an error reporting service
const logger = getLogger(`400 error page`)
logger.level = 'error'
logger.error(error)
console.log(error, errorInfo)
}
render() {
Iif (this.state.hasError) {
// Custom fallback UI
return (
<ErrorPage
lang={'en'}
errType="500"
isAuth={false}
homePageLink={'/en/my-dashboard'}
accountPageLink="/"
/>
)
}
return this.props.children
}
}
export default ErrorBoundary
|