import { AlertCircle, RefreshCw } from "lucide-react"; import { Component, type ErrorInfo, type ReactNode } from "react"; import { useRouteError } from "react-router-dom"; import { Button } from "./ui/button"; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error: Error | null; } 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, errorInfo: ErrorInfo) { console.error("ErrorBoundary caught an error:", error, errorInfo); } handleReset = () => { this.setState({ hasError: false, error: null }); window.location.reload(); }; render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

Something went wrong

An unexpected error occurred. This could be due to a network issue or a problem with the application.

{this.state.error && (
Error details
{this.state.error.message}
)}
); } return this.props.children; } } // React Router errorElement for route-level errors (e.g., failed chunk loads after redeployment). export function ChunkLoadErrorFallback() { const error = useRouteError() as Error | undefined; return (

Something went wrong

An unexpected error occurred. This could be due to a network issue or an application update. Reloading usually fixes it.

{error?.message && (
Error details
{error.message}
)}
); }