import React, { Component, ErrorInfo, ReactNode } from 'react'; import { AlertTriangle, Home, RefreshCw } from 'lucide-react'; import { Link } from 'react-router-dom'; import { Button } from '@/components/ui/button'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; } class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null, errorInfo: null, }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error, errorInfo: null, }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('ErrorBoundary caught an error:', error, errorInfo); this.setState({ error, errorInfo, }); } handleReset = () => { this.setState({ hasError: false, error: null, errorInfo: null, }); }; render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

Algo salió mal

La aplicación encontró un error inesperado. Por favor, intenta recargar la página.

{import.meta.env.DEV && this.state.error && (

{this.state.error.toString()}

{this.state.errorInfo && (
                    {this.state.errorInfo.componentStack}
                  
)}
)}
); } return this.props.children; } } export default ErrorBoundary;