import React, { Component, type ReactNode } from 'react'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error?: Error; } /** * Concise Error Boundary following DRY principles */ export class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { // Simplified error reporting console.error('UI Error:', error, errorInfo); // Optional: Report to backend fetch('/api/error-report', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ error: error.message, stack: error.stack, timestamp: new Date().toISOString() }) }).catch(() => {}); // Silent fail for error reporting } render() { if (this.state.hasError) { return this.props.fallback || (
⚠️

Something went wrong

The chat component encountered an error. Please refresh the page and try again.

); } return this.props.children; } }