diff --git a/src/components/common/ErrorBoundary.jsx b/src/components/common/ErrorBoundary.jsx new file mode 100644 index 00000000..677a67fa --- /dev/null +++ b/src/components/common/ErrorBoundary.jsx @@ -0,0 +1,59 @@ +'use client' + +import React from 'react' + +class ErrorBoundary extends React.Component { + constructor(props) { + super(props) + this.state = { hasError: false, error: null, errorInfo: null } + } + + static getDerivedStateFromError(error) { + // Update state so the next render will show the fallback UI + return { hasError: true } + } + + componentDidCatch(error, errorInfo) { + // Log detailed error information + console.error('🚨 React Error Boundary caught an error:', { + error, + errorInfo, + timestamp: new Date().toISOString(), + componentStack: errorInfo.componentStack, + errorStack: error.stack + }) + + this.setState({ + error: error, + errorInfo: errorInfo + }) + } + + render() { + if (this.state.hasError) { + // You can render any custom fallback UI + return ( +
Timestamp: {new Date().toISOString()}
+Error: {this.state.error && this.state.error.toString()}
+Stack Trace:
+{this.state.errorInfo.componentStack}
+