import { Typography } from '@material-ui/core'; import { TFunction } from 'i18next'; import React, { Component, Fragment } from 'react'; import { withTranslation } from 'react-i18next'; import { Link } from 'react-router-dom'; import { ROOT } from '../../../constants/routes'; import LoggerContext from '../../../contexts/logger'; import { LoggerFacade } from '../../../services/logger/Facade'; export interface Props { readonly children: any; readonly t: TFunction; readonly logger: LoggerFacade; } export interface State { readonly hasError: boolean; } class ErrorBoundary extends Component { public state = { hasError: false }; // tslint:disable-next-line:prefer-function-over-method public componentDidCatch(error: any, errorInfo: any) { this.props.logger.captureException(error, errorInfo); this.setState({ hasError: true }); } public handleClick = () => this.setState({ hasError: false, }); public render() { const { children, t } = this.props; const element = React.isValidElement(children) ? React.Children.map(children, (child: any) => React.cloneElement(child, this.props) ) : children; if (this.state.hasError) { return ( {t('global.somethingWentWrong')} {t('global.refreshThePage')} ); } return element; } } export default withTranslation()((props: any) => ( {logger => } ));