diff --git a/src/AppContent.jsx b/src/AppContent.jsx index 64eff37..e0f55ce 100644 --- a/src/AppContent.jsx +++ b/src/AppContent.jsx @@ -26,6 +26,8 @@ import Contributors from "./pages/Contributors.jsx"; import DocsHub from "./pages/DocsHub.jsx"; import SettingsMenu from "./components/SettingsMenu.jsx"; import ChatBot from "./components/ChatBot.jsx"; +import ErrorBoundary from "./components/ErrorBoundary.jsx"; +import NotFound from "./pages/NotFound.jsx"; import { Ion } from "cesium"; import useSettings from "./hooks/UseSettings.jsx"; import Loader from "./components/Loader.jsx"; @@ -52,27 +54,30 @@ const AppContent = () => { {!hideNavbarRoutes.includes(location.pathname) && } -
- - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - -
+ +
+ + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + +
+
); }; diff --git a/src/components/ErrorBoundary.jsx b/src/components/ErrorBoundary.jsx new file mode 100644 index 0000000..d21c600 --- /dev/null +++ b/src/components/ErrorBoundary.jsx @@ -0,0 +1,113 @@ +import React from 'react'; +import { AlertTriangle, RefreshCw, Home } from 'lucide-react'; +import { useNavigate } from 'react-router-dom'; + +class ErrorBoundary extends React.Component { + constructor(props) { + super(props); + this.state = { + hasError: false, + error: null, + errorInfo: null + }; + } + + static getDerivedStateFromError(error) { + // Update state so the next render will show the fallback UI + return { hasError: true }; + } + + componentDidCatch(error, errorInfo) { + // Log error details for debugging + console.error('Error Boundary caught an error:', error, errorInfo); + + this.setState({ + error, + errorInfo + }); + + // You can also log to an error reporting service here + // logErrorToService(error, errorInfo); + } + + render() { + if (this.state.hasError) { + return this.setState({ hasError: false, error: null, errorInfo: null })} />; + } + + return this.props.children; + } +} + +// Error Fallback UI Component +const ErrorFallback = ({ error, resetError }) => { + const navigate = useNavigate(); + + const handleReset = () => { + resetError(); + window.location.reload(); + }; + + const handleGoHome = () => { + resetError(); + navigate('/'); + }; + + return ( +
+
+ {/* Icon */} +
+
+ +
+
+ + {/* Title */} +

+ Oops! Something went wrong +

+ + {/* Description */} +

+ We encountered an unexpected error. Our team has been notified and we're working on a fix. +

+ + {/* Error Details (in development mode) */} + {process.env.NODE_ENV === 'development' && error && ( +
+

+ {error.toString()} +

+
+ )} + + {/* Action Buttons */} +
+ + + +
+ + {/* Support Message */} +

+ If this problem persists, please contact our support team. +

+
+
+ ); +}; + +export default ErrorBoundary;