import React, { ErrorInfo, ReactNode } from 'react'; import { Card } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; interface Props { children: ReactNode; } interface State { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; } class SigmaErrorBoundary extends React.Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null, errorInfo: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error, errorInfo: null }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Sigma.js Error Boundary caught an error:', { error, errorInfo, timestamp: new Date().toISOString(), userAgent: navigator.userAgent, url: window.location.href }); this.setState({ error, errorInfo }); // Report to monitoring service if (process.env.NODE_ENV === 'production') { // Analytics or error reporting service this.reportError(error, errorInfo); } } private reportError(error: Error, errorInfo: ErrorInfo) { // Implement your error reporting logic here console.log('Reporting error to monitoring service:', { error, errorInfo }); } private handleRetry = () => { this.setState({ hasError: false, error: null, errorInfo: null }); }; render() { if (this.state.hasError) { return (
🔧

Knowledge Graph Error

The graph visualization encountered an error and cannot be displayed.

{process.env.NODE_ENV === 'development' && this.state.error && (

Error Details (Development Mode)

                  {this.state.error.toString()}
                  {this.state.errorInfo?.componentStack}
                
)}
); } return this.props.children; } } export default SigmaErrorBoundary;