import React from 'react'; import { logError } from '@/utils/errorLogger'; interface ErrorBoundaryProps { children: React.ReactNode; fallback?: React.ReactNode; } interface ErrorBoundaryState { hasError: boolean; error: Error | null; } /** * App-wide ErrorBoundary that catches React rendering errors * and displays a fallback UI with a reload button. */ export class ErrorBoundary extends React.Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void { console.error('[ErrorBoundary] Uncaught error:', error, errorInfo); logError(error, { componentStack: errorInfo.componentStack, source: 'ErrorBoundary' }); } handleReload = (): void => { window.location.reload(); }; render(): React.ReactNode { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

Ein Fehler ist aufgetreten

Die Anwendung konnte nicht geladen werden. Bitte versuchen Sie es erneut.

{this.state.error && (
Fehlerdetails
                  {this.state.error.message}
                  {this.state.error.stack && `\n\n${this.state.error.stack}`}
                
)}
); } return this.props.children; } } export default ErrorBoundary;