Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(dashboard): add ErrorBoundary for graceful crash recovery

rmyndharis1b9ad8267b86
diff --git a/dashboard/src/App.tsx b/dashboard/src/App.tsx
index 20dd2b500..ada45d27e 100644
--- a/dashboard/src/App.tsx
+++ b/dashboard/src/App.tsx
@@ -12,6 +12,7 @@ import { Infrastructure } from './pages/Infrastructure';
import Plugins from './pages/Plugins';
import { ToastProvider } from './components/Toast';
import { RoleProvider, useRole, type UserRole } from './hooks/useRole';
+import { ErrorBoundary } from './components/ErrorBoundary';
import './App.css';
function AppContent() {
@@ -96,9 +97,11 @@ function AppContent() {
function App() {
return (
- <RoleProvider>
- <AppContent />
- </RoleProvider>
+ <ErrorBoundary>
+ <RoleProvider>
+ <AppContent />
+ </RoleProvider>
+ </ErrorBoundary>
);
}
diff --git a/dashboard/src/components/ErrorBoundary.tsx b/dashboard/src/components/ErrorBoundary.tsx
new file mode 100644
index 000000000..d3e9fe5b8
--- /dev/null
+++ b/dashboard/src/components/ErrorBoundary.tsx
@@ -0,0 +1,62 @@
+import { Component, type ReactNode, type ErrorInfo } from 'react';
+import { AlertCircle, RefreshCw } from 'lucide-react';
+
+interface Props {
+ children: ReactNode;
+}
+
+interface State {
+ hasError: boolean;
+ error: Error | null;
+}
+
+export class ErrorBoundary extends Component<Props, State> {
+ constructor(props: Props) {
+ super(props);
+ this.state = { hasError: false, error: null };
+ }
+
+ static getDerivedStateFromError(error: Error): State {
+ return { hasError: true, error };
+ }
+
+ componentDidCatch(error: Error, errorInfo: ErrorInfo) {
+ console.error('[ErrorBoundary] Uncaught error:', error, errorInfo);
+ }
+
+ handleReload = () => {
+ window.location.reload();
+ };
+
+ render() {
+ if (this.state.hasError) {
+ return (
+ <div style={{
+ display: 'flex', flexDirection: 'column', alignItems: 'center',
+ justifyContent: 'center', minHeight: '100vh', padding: '2rem',
+ fontFamily: 'system-ui, sans-serif', color: '#374151',
+ }}>
+ <AlertCircle size={48} style={{ color: '#DC2626', marginBottom: '1rem' }} />
+ <h1 style={{ fontSize: '1.5rem', marginBottom: '0.5rem' }}>Something went wrong</h1>
+ <p style={{ color: '#6B7280', marginBottom: '1.5rem', textAlign: 'center' }}>
+ The dashboard encountered an unexpected error.
+ </p>
+ <button
+ onClick={this.handleReload}
+ style={{
+ display: 'flex', alignItems: 'center', gap: '0.5rem',
+ padding: '0.75rem 1.5rem', backgroundColor: '#2563EB',
+ color: 'white', border: 'none', borderRadius: '0.5rem',
+ cursor: 'pointer', fontSize: '1rem',
+ }}
+ >
+ <RefreshCw size={18} />
+ Reload Dashboard
+ </button>
+ </div>
+ );
+ }
+
+ return this.props.children;
+ }
+}