import React from 'react'; import { AlertTriangle, RefreshCw } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; // ──────────────────────────────────────────────────────────────────────────── // ErrorBoundary Component // ──────────────────────────────────────────────────────────────────────────── class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false, error: null, componentStack: null }; } static getDerivedStateFromError(error) { return { hasError: true, error }; } componentDidCatch(error, info) { console.error('ErrorBoundary caught an error:', { error, componentStack: info?.componentStack, }); this.setState({ error, componentStack: info?.componentStack }); } handleReset = () => { this.setState({ hasError: false, error: null, componentStack: null }); }; handleReload = () => { window.location.reload(); }; render() { if (!this.state.hasError) { return this.props.children; } const { error, componentStack } = this.state; return (

Something went wrong

An unexpected error occurred. You can try to recover by reloading the page or resetting this component.

{error && (

Error Message

                {String(error)}
              
)} {componentStack && (

Component Stack (for debugging)

                {componentStack}
              
)}
); } } // ──────────────────────────────────────────────────────────────────────────── //withErrorBoundary HOC // ──────────────────────────────────────────────────────────────────────────── export function withErrorBoundary(Component, displayName = Component.name || 'Component') { function WrappedComponent(props) { return ( ); } WrappedComponent.displayName = `withErrorBoundary(${displayName})`; return WrappedComponent; } export default ErrorBoundary;