'use client' import React from 'react' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { AlertTriangle, RefreshCw } from 'lucide-react' interface ErrorBoundaryState { hasError: boolean error?: Error errorInfo?: React.ErrorInfo } interface ErrorBoundaryProps { children: React.ReactNode fallback?: React.ComponentType<{error?: Error; resetError: () => void}> } export class ErrorBoundary extends React.Component { constructor(props: ErrorBoundaryProps) { super(props) this.state = { hasError: false } } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error } } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error('Error caught by boundary:', error, errorInfo) this.setState({ error, errorInfo }) } resetError = () => { this.setState({ hasError: false, error: undefined, errorInfo: undefined }) } render() { if (this.state.hasError) { if (this.props.fallback) { const FallbackComponent = this.props.fallback return } return (
Something went wrong An unexpected error occurred. Please try refreshing the page.
{process.env.NODE_ENV === 'development' && this.state.error && (
Error Details
                    {this.state.error.toString()}
                  
)}
) } return this.props.children } } // Hook version for functional components export function useErrorBoundary() { return (error: Error) => { throw error } }