import React from "react"; import {trackEvent} from "@/Utils"; interface ErrorBoundaryState { hasError: boolean; errorMessage?: string; } interface ErrorBoundaryProps { children: React.ReactNode; } export default class ErrorBoundary extends React.Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, errorMessage: error.message }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error("Caught an error:", error, errorInfo); trackEvent("error", { error: error.message, errorInfo: JSON.stringify(errorInfo) }); } render() { if (this.state.hasError) { // Render any custom fallback UI with the error message return (

Something went wrong.

Error: {this.state.errorMessage}

); } return this.props.children; } }