import { reportClientError } from "@/lib/errorReporting"; import { Component, type ReactNode } from "react"; import { Layout } from "@/components/Layout"; import { AlertTriangle, RefreshCw } from "lucide-react"; interface Props { children: ReactNode; fallbackMessage?: string; } interface State { hasError: boolean; error: Error | null; } /** * L-2: Catches rendering errors and shows a friendly fallback UI * instead of a white screen. Works as a wrapper around page content. */ export class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, info: React.ErrorInfo) { console.error("[ErrorBoundary]", error, info.componentStack); reportClientError("react", error); } handleReset = () => { this.setState({ hasError: false, error: null }); }; render() { if (this.state.hasError) { return (

Something went wrong

{this.props.fallbackMessage || "An unexpected error occurred while rendering this page. Please try again."}

{this.state.error && (
Technical details
                  {this.state.error.message}
                
)}
); } return this.props.children; } }