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 (
An unexpected error occurred. You can try to recover by reloading the page or resetting this component.
{error && (Error Message
{String(error)}
Component Stack (for debugging)
{componentStack}