import React, { Component, ReactNode } from "react"; import { AlertCircle } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; interface ErrorBoundaryProps { children: ReactNode; fallback?: (error: Error, reset: () => void) => ReactNode; } interface ErrorBoundaryState { hasError: boolean; error: Error | null; } /** * Error Boundary component to catch and display React rendering errors */ export class ErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): ErrorBoundaryState { // Update state so the next render will show the fallback UI return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { // Log the error to console console.error("Error caught by boundary:", error, errorInfo); } reset = () => { this.setState({ hasError: false, error: null }); }; render() { if (this.state.hasError && this.state.error) { // Use custom fallback if provided if (this.props.fallback) { return this.props.fallback(this.state.error, this.reset); } // Default error UI return (

Something went wrong

An error occurred while rendering this component.

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