import { Component, ErrorInfo, ReactNode } from 'react'; import i18n from '../i18n'; interface Props { children: ReactNode; } interface State { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; } export class ErrorBoundary extends Component { public state: State = { hasError: false, error: null, errorInfo: null }; public static getDerivedStateFromError(error: Error): State { return { hasError: true, error, errorInfo: null }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { this.setState({ error, errorInfo }); console.error('Uncaught error:', error, errorInfo); } public render() { if (this.state.hasError) { return (

{i18n.t($ => $.dialogs.errorBoundary.title)}

{i18n.t($ => $.dialogs.errorBoundary.description)}
{this.state.error && this.state.error.toString()}
{this.state.errorInfo && this.state.errorInfo.componentStack}
); } return this.props.children; } }