"use client" import { Component, ReactNode } from "react" import { AlertCircle, RefreshCw } from "lucide-react" import { Button } from "@/components/ui/button" import { Card, CardContent } from "@/components/ui/card" interface ErrorBoundaryProps { children: ReactNode fallback?: ReactNode section?: string } interface ErrorBoundaryState { hasError: boolean error: Error | null } /** * Reusable error boundary for per-section error recovery. * Prevents a single component crash from taking down the entire page. * * Usage: * * * */ export class ErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props) this.state = { hasError: false, error: null } } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error } } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error(`[ErrorBoundary${this.props.section ? `: ${this.props.section}` : ''}]`, error, errorInfo) } handleRetry = () => { this.setState({ hasError: false, error: null }) } render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback } return ( {this.props.section ? `Error loading ${this.props.section}` : 'Something went wrong'} This section encountered an error. The rest of the page still works. Retry ) } return this.props.children } }
This section encountered an error. The rest of the page still works.