import React from 'react' ; import { withRouter } from 'react-router-dom' ; type Props = any ; type State = { hasError : boolean ; sentry : any ; } ; class ErrorBoundary extends React . Component < Props , State > { constructor ( props ) { super ( props ) ; this . state = { hasError : false , sentry : null } ; } static getDerivedStateFromError ( ) { return { hasError : true } ; } componentDidCatch ( error , errorInfo ) { if ( this . state . sentry ) { this . state . sentry . captureException ( error ) ; this . props . history . push ( '/error' ) ; } } componentDidMount ( ) { import ( '@/utils/sentry' ) . then ( ( { default : Sentry } ) => { this . setState ( { sentry : Sentry } ) ; } ) ; } render ( ) { return this . props . children ; } } export default withRouter ( ErrorBoundary ) ;