import { Component, ErrorInfo, ReactNode } from 'react'; import { useErrorHandler } from '../../hooks/useErrorHandler'; interface Props { children: ReactNode; fallback?: ReactNode; pageName?: string; } interface State { hasError: boolean; error: Error | null; } export class PageErrorBoundary extends Component { 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(`[${this.props.pageName || 'Page'}] Error:`, error, errorInfo); // Error will be caught by GlobalErrorDisplay via useErrorHandler } render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (
⚠️

Something went wrong

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

{import.meta.env.DEV && this.state.error && (
Error Details (Dev Mode)
                  {this.state.error.stack}
                
)}
); } return this.props.children; } }