diff --git a/client/src/components/ErrorBoundary.jsx b/client/src/components/ErrorBoundary.jsx new file mode 100644 index 00000000..9ae96ce9 --- /dev/null +++ b/client/src/components/ErrorBoundary.jsx @@ -0,0 +1,61 @@ +import React from 'react'; + +class ErrorBoundary extends React.Component { + constructor(props) { + super(props); + this.state = { hasError: false, error: null }; + } + + static getDerivedStateFromError(error) { + // Update state so the next render will show the fallback UI. + return { hasError: true, error }; + } + + componentDidCatch(error, errorInfo) { + // You can also log the error to an error reporting service + console.error("ErrorBoundary caught an error:", error, errorInfo); + } + + handleReload = () => { + window.location.reload(); + }; + + render() { + if (this.state.hasError) { + return ( +
+ {this.state.error?.message || "An unexpected application error occurred."} +
+ +