"use client"; import { Component, type ReactNode, type ErrorInfo } from "react"; interface Props { children: ReactNode; fallback?: ReactNode; onError?: (error: Error, info: ErrorInfo) => void; } interface State { error: Error | null; } export class ErrorBoundary extends Component { state: State = { error: null }; static getDerivedStateFromError(error: Error): State { return { error }; } componentDidCatch(error: Error, info: ErrorInfo) { console.error("[ErrorBoundary]", error, info.componentStack); this.props.onError?.(error, info); } render() { if (this.state.error) { return ( this.props.fallback ?? ( this.setState({ error: null })} /> ) ); } return this.props.children; } } export function DefaultErrorFallback({ error, reset, }: { error: Error; reset: () => void; }) { return (

Something went wrong

{error.message || "An unexpected error occurred. The team has been notified."}

); }