| 12 | } |
| 13 | |
| 14 | export class ErrorBoundary extends Component<Props, State> { |
| 15 | constructor(props: Props) { |
| 16 | super(props); |
| 17 | this.state = { hasError: false, error: null }; |
| 18 | } |
| 19 | |
| 20 | static getDerivedStateFromError(error: Error): State { |
| 21 | return { hasError: true, error }; |
| 22 | } |
| 23 | |
| 24 | componentDidCatch(error: Error, info: ErrorInfo) { |
| 25 | console.error("ErrorBoundary caught:", error, info.componentStack); |
| 26 | } |
| 27 | |
| 28 | render() { |
| 29 | if (this.state.hasError) { |
| 30 | return ( |
| 31 | this.props.fallback ?? ( |
| 32 | <div className="flex items-center justify-center h-full"> |
| 33 | <div className="text-center p-8 max-w-md"> |
| 34 | <p className="text-red-400 text-lg font-medium mb-2"> |
| 35 | Rendering error |
| 36 | </p> |
| 37 | <p className="text-white/50 text-sm font-mono"> |
| 38 | {this.state.error?.message ?? "Unknown error"} |
| 39 | </p> |
| 40 | <button |
| 41 | onClick={() => this.setState({ hasError: false, error: null })} |
| 42 | className="mt-4 px-4 py-2 bg-white/10 hover:bg-white/20 rounded text-sm transition-colors" |
| 43 | > |
| 44 | Retry |
| 45 | </button> |
| 46 | </div> |
| 47 | </div> |
| 48 | ) |
| 49 | ); |
| 50 | } |
| 51 | return this.props.children; |
| 52 | } |
| 53 | } |
nothing calls this directly
no outgoing calls
no test coverage detected