/** * Error Boundary component to catch React errors */ import { Component, type ReactNode } from 'react'; interface ErrorBoundaryProps { children: ReactNode; fallback?: (error: Error, resetError: () => void) => ReactNode; } interface ErrorBoundaryState { hasError: boolean; error: Error | null; } /** * Error boundary that catches React errors and displays a fallback UI */ export class ErrorBoundary extends 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('Error boundary caught error:', error, errorInfo); } resetError = (): void => { this.setState({ hasError: false, error: null, }); }; render(): ReactNode { if (this.state.hasError && this.state.error) { if (this.props.fallback) { return this.props.fallback(this.state.error, this.resetError); } return (
⚠️

Something went wrong

An unexpected error occurred. Please try refreshing the page.

Error details
                {this.state.error.toString()}
                {this.state.error.stack && `\n\n${this.state.error.stack}`}
              
); } return this.props.children; } }