import { Component, ErrorInfo, ReactNode } from 'react'; import { AlertCircle, RefreshCw } from 'lucide-react'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; } class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null, errorInfo: null, }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error, errorInfo: null, }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('ErrorBoundary caught an error:', error, errorInfo); this.setState({ error, errorInfo, }); } handleReset = () => { this.setState({ hasError: false, error: null, errorInfo: null, }); window.location.reload(); }; render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

An Error Occurred

Sorry, an error has occurred. Please try again or contact support if the problem persists.

{process.env.NODE_ENV === 'development' && this.state.error && (

{this.state.error.toString()}

{this.state.errorInfo && (
Error Details
                      {this.state.errorInfo.componentStack}
                    
)}
)}
); } return this.props.children; } } export default ErrorBoundary;