import React, { Component, type ReactNode } from 'react'; import { browserLog } from '@/utils/browserLog'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error?: Error; } export class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } override componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { browserLog.error('ErrorBoundary caught an error:', error, errorInfo); } override render() { if (this.state.hasError) { return ( this.props.fallback || (

Something went wrong

{this.state.error?.message || 'An unexpected error occurred'}

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