'use client'; import React, { Component, ErrorInfo, ReactNode } from 'react'; interface Props { children: ReactNode; fallback?: ReactNode; name?: string; } interface State { hasError: boolean; error: Error | null; } class ErrorBoundary 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( `[ErrorBoundary${this.props.name ? `: ${this.props.name}` : ''}]`, error, errorInfo, ); } render() { if (this.state.hasError) { if (this.props.fallback) return this.props.fallback; return (
⚠ SYSTEM ERROR
{this.props.name || 'Component'} failed to render
); } return this.props.children; } } export default ErrorBoundary;