// ErrorBoundary Component // Catches JavaScript errors anywhere in the child component tree and displays a fallback UI class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false, error: null, errorInfo: null }; } static getDerivedStateFromError(error) { // Update state so the next render shows the fallback UI return { hasError: true, error }; } componentDidCatch(error, errorInfo) { // Log error details for debugging console.error('ErrorBoundary caught an error:', error, errorInfo); this.setState({ errorInfo }); // Optional: Send to error reporting service if (this.props.onError) { this.props.onError(error, errorInfo); } } handleRetry = () => { this.setState({ hasError: false, error: null, errorInfo: null }); }; handleReload = () => { window.location.reload(); }; render() { if (this.state.hasError) { // Custom fallback UI if provided if (this.props.fallback) { return this.props.fallback; } const { error, errorInfo } = this.state; const isDev = window.location.hostname === 'localhost'; return (
{/* Error Card */}
{/* Header */}

Qualcosa è andato storto

Si è verificato un errore imprevisto nell'applicazione

{/* Content */}
{/* Error message for developers */} {isDev && error && (

Dettagli errore (dev only)

{error.toString()}

{errorInfo?.componentStack && (
                                                {errorInfo.componentStack}
                                            
)}
)} {/* Action buttons */}
{/* Help text */}

Se il problema persiste, contatta il supporto tecnico

{/* Footer hint */}

Premi F12 per aprire la console e vedere i dettagli dell'errore

); } return this.props.children; } } // Smaller inline error boundary for sections class SectionErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error) { return { hasError: true, error }; } componentDidCatch(error, errorInfo) { console.error('SectionErrorBoundary caught an error:', error, errorInfo); } handleRetry = () => { this.setState({ hasError: false, error: null }); }; render() { if (this.state.hasError) { return (

{this.props.sectionName || 'Questa sezione'} non è disponibile

Si è verificato un errore durante il caricamento

); } return this.props.children; } } window.ErrorBoundary = ErrorBoundary; window.SectionErrorBoundary = SectionErrorBoundary;