/** * ErrorBoundary - Global error boundary component. * * Catches uncaught JavaScript errors in the component tree below it * and renders a fallback UI instead of crashing the entire application. * Provides a "Try again" recovery action that resets the error state. * * This is a React class component because error boundaries require * componentDidCatch / getDerivedStateFromError lifecycle methods. */ import { Component } from "react"; import PropTypes from "prop-types"; import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; class ErrorBoundary extends Component { constructor(props) { super(props); this.state = { hasError: false, error: null, errorInfo: null, }; } static getDerivedStateFromError(error) { return { hasError: true, error }; } componentDidCatch(error, errorInfo) { this.setState({ errorInfo }); // Log to console in development; in production this would // integrate with an error tracking service (Sentry, etc.). console.error("[ErrorBoundary] Caught error:", error, errorInfo); } handleReset = () => { this.setState({ hasError: false, error: null, errorInfo: null }); }; handleReload = () => { window.location.reload(); }; render() { if (this.state.hasError) { // Custom fallback if provided if (this.props.fallback) { return this.props.fallback({ error: this.state.error, reset: this.handleReset, }); } // Default fallback UI return (

Something went wrong

An unexpected error occurred. This has been noted and we are working to fix it. Please try again or reload the page.

{this.state.error && (
Error Details
                  {this.state.error.toString()}
                
)}
); } return this.props.children; } } ErrorBoundary.propTypes = { children: PropTypes.node.isRequired, fallback: PropTypes.func, }; export default ErrorBoundary;