import React, { Component, type ErrorInfo, type ReactNode } from 'react'; import { AlertTriangle, RefreshCw } from 'lucide-react'; import { Button } from './ui'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error?: Error; errorInfo?: ErrorInfo; } export class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { this.setState({ error, errorInfo }); // Log error to monitoring service in production if (process.env.NODE_ENV === 'production') { console.error('Error caught by boundary:', error, errorInfo); // TODO: Send to error monitoring service (Sentry, LogRocket, etc.) } } handleReset = () => { this.setState({ hasError: false, error: undefined, errorInfo: undefined }); }; render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

Oops! Something went wrong

We encountered an unexpected error. Please try refreshing the page or contact support if the problem persists.

{process.env.NODE_ENV === 'development' && this.state.error && (
Debug Information
                    {this.state.error.toString()}
                    {this.state.errorInfo?.componentStack}
                  
)}
); } return this.props.children; } }