import React, { Component, ErrorInfo, ReactNode } from "react"; import { mdiAlertCircle } from "@mdi/js"; import BaseIcon from "./BaseIcon"; type ErrorBoundaryProps = { children: ReactNode; }; type ErrorBoundaryState = { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; showStack: boolean; }; class ErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false, error: null, errorInfo: null, showStack: false, }; } static getDerivedStateFromError(error: Error): Partial { return { hasError: true, error, }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error("Error caught in boundary:", error, errorInfo); this.setState({ errorInfo, }); } toggleStack = () => { this.setState((prevState) => ({ showStack: !prevState.showStack, })); }; resetError = () => { this.setState({ hasError: false, error: null, errorInfo: null, showStack: false, }); }; render() { if (!this.state.hasError) { return this.props.children; } const { error, errorInfo, showStack } = this.state; const errorMessage = error?.message || "An unexpected error occurred"; const stackTrace = errorInfo?.componentStack || error?.stack || "No stack trace available"; return (

Something went wrong

The app stopped on a visible frontend error.

{errorMessage}
{showStack && (
              {stackTrace}
            
)}
); } } export default ErrorBoundary;