import React, { Component, ReactNode } from "react"; import { Button } from "./ui/button"; import { AlertTriangle, RefreshCw, Home, Code } from "lucide-react"; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error: Error | null; errorInfo: React.ErrorInfo | null; } export class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null, errorInfo: null, }; } static getDerivedStateFromError(error: Error): Partial { return { hasError: true }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error("Error caught by boundary:", 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 (
{/* Main Error Card */}
{/* Header with Gradient */}
{/* Animated Icon */}

Oops! Something went wrong

Don't worry, your data is safe. The error has been logged and we'll look into it.

{/* Error Details */}
{this.state.error && (
{/* Error Message */}

Error Message

                          {this.state.error.toString()}
                        
{/* Stack Trace (Dev Only) */} {import.meta.env.DEV && this.state.errorInfo && (
Stack Trace (Development Mode)
                            {this.state.errorInfo.componentStack}
                          
)}
)} {/* Action Buttons */}
{/* Help Text */}

If this problem persists, please contact support or check the console for more details.

{/* Additional Help Card */}

Quick Troubleshooting

  • Try clearing your browser cache and cookies
  • Check your internet connection
  • Make sure you're using a supported browser
  • Disable browser extensions that might interfere
); } return this.props.children; } }