diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 0562910..a05ddaa 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -8,10 +8,12 @@ import SignUp from "./pages/Signup.js"; import SignIn from "./pages/Signin.js"; import OAuthSuccess from "./pages/OAuthSuccess.js"; import RoomActions from "./pages/RoomActions.js"; +import ErrorBoundary from "./components/ErrorBoundary.js"; import "./index.css" const queryClient = new QueryClient(); const App = () => ( + @@ -27,6 +29,7 @@ const App = () => ( + ); export default App; \ No newline at end of file diff --git a/frontend/src/components/ErrorBoundary.tsx b/frontend/src/components/ErrorBoundary.tsx new file mode 100644 index 0000000..2681348 --- /dev/null +++ b/frontend/src/components/ErrorBoundary.tsx @@ -0,0 +1,75 @@ +import React, { Component, ReactNode } from "react"; +import { AlertTriangle } from "lucide-react"; +interface Props { + children: ReactNode; + fallback?: ReactNode; +} + +interface State { + hasError: boolean; + error?: Error; +} + +class ErrorBoundary extends Component { + declare props: Readonly; + state: State = { hasError: false }; + + constructor(props: Props) { + super(props); + } + static getDerivedStateFromError(error: Error): State { + return { hasError: true, error }; + } + handleReload = () => { + window.location.reload(); + }; + render() { + const { hasError, error } = this.state; + const { children, fallback } = this.props; + + if (hasError) { + return ( + fallback ?? ( +
+
+
+
+ +
+
+ +

+ Oops! Something went wrong +

+

+ {error?.message ?? "An unexpected error occurred. Please try again."} +

+ +
+ + +
+
+ +

+ If the issue persists, please contact support. +

+
+ ) + ); + } + + return children; + } +} +export default ErrorBoundary;