diff --git a/frontend/src/components/shared/ErrorBoundary.jsx b/frontend/src/components/shared/ErrorBoundary.jsx new file mode 100644 index 0000000..9379805 --- /dev/null +++ b/frontend/src/components/shared/ErrorBoundary.jsx @@ -0,0 +1,71 @@ +import React from 'react'; + +class ErrorBoundary extends React.Component { + constructor(props) { + super(props); + this.state = { hasError: false, error: null, errorInfo: null }; + } + + static getDerivedStateFromError(error) { + return { hasError: true, error }; + } + + componentDidCatch(error, errorInfo) { + console.error("ErrorBoundary caught an error", error, errorInfo); + this.setState({ errorInfo }); + } + + handleReset = () => { + this.setState({ hasError: false, error: null, errorInfo: null }); + window.location.href = '/'; + }; + + render() { + if (this.state.hasError) { + return ( +
+ CodeLens encountered an unexpected error. Don't worry, your progress has not been lost. +
+ + {this.state.error && ( +{this.state.error.toString()}
+ {this.state.errorInfo && ( +{this.state.errorInfo.componentStack}
+ )}
+