From 7fa6ed1a68c428b1e93a1417b6549e0d7a53cbde Mon Sep 17 00:00:00 2001 From: Sadeeq~ Date: Sun, 31 May 2026 10:54:19 +0100 Subject: [PATCH] feat(frontend): implement global error boundary for issue #348 --- .../src/components/GlobalErrorBoundary.tsx | 71 +++++++++++++++++++ dashboard/src/main.tsx | 5 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 dashboard/src/components/GlobalErrorBoundary.tsx diff --git a/dashboard/src/components/GlobalErrorBoundary.tsx b/dashboard/src/components/GlobalErrorBoundary.tsx new file mode 100644 index 0000000..bc667b4 --- /dev/null +++ b/dashboard/src/components/GlobalErrorBoundary.tsx @@ -0,0 +1,71 @@ +import React, { Component, ReactNode, ErrorInfo } from 'react'; +import { AlertTriangle, RefreshCcw } from 'lucide-react'; + +interface Props { + children?: ReactNode; +} + +interface State { + hasError: boolean; + error: Error | null; +} + +export class GlobalErrorBoundary extends Component { + public state: State = { + hasError: false, + error: null, + }; + + public static getDerivedStateFromError(error: Error): State { + return { hasError: true, error }; + } + + public componentDidCatch(error: Error, errorInfo: ErrorInfo) { + console.error('Uncaught error:', error, errorInfo); + } + + private handleReload = () => { + window.location.reload(); + }; + + public render() { + if (this.state.hasError) { + return ( +
+
+
+ +
+ +
+

System Error

+

+ An unexpected error occurred while rendering the application interface. Our team has been notified. +

+
+ + {this.state.error && ( +
+

+ {this.state.error.toString()} +

+
+ )} + + +
+
+ ); + } + + return this.props.children; + } +} + +export default GlobalErrorBoundary; diff --git a/dashboard/src/main.tsx b/dashboard/src/main.tsx index 964aeb4..b9f06bf 100644 --- a/dashboard/src/main.tsx +++ b/dashboard/src/main.tsx @@ -1,10 +1,13 @@ import React from 'react' import ReactDOM from 'react-dom/client' import App from './App' +import GlobalErrorBoundary from './components/GlobalErrorBoundary' import './index.css' ReactDOM.createRoot(document.getElementById('root')!).render( - + + + , )