"use client"; import React from "react"; import { AlertTriangle, RotateCcw } from "lucide-react"; import { Button } from "@/components/ui/button"; interface Props { children: React.ReactNode; fallback?: React.ReactNode; } interface State { hasError: boolean; error?: Error; } export class ErrorBoundary extends React.Component { constructor(props: Props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error("ErrorBoundary caught an error:", error, errorInfo); } resetError = () => { this.setState({ hasError: false, error: undefined }); }; render() { if (this.state.hasError) { if (this.props.fallback) return this.props.fallback; return (

Something went wrong

{this.state.error?.message || "An unexpected error occurred while rendering this component."}

); } return this.props.children; } }