/** * Error Boundary Components * * Provides graceful error handling for crypto and API operations */ import { Icon } from '@iconify/react'; import { Alert, Box, Button, Typography } from '@mui/material'; import React, { Component, ReactNode } from 'react'; interface ErrorBoundaryProps { children: ReactNode; fallback?: ReactNode; onReset?: () => void; } interface ErrorBoundaryState { hasError: boolean; error?: Error; errorInfo?: React.ErrorInfo; } /** * Base error boundary component */ abstract class BaseErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error('Error caught by boundary:', error, errorInfo); console.error('Error type:', typeof error); console.error('Error keys:', Object.keys(error)); console.error('Error message:', error.message); console.error('Error toString:', String(error)); this.setState({ errorInfo }); } handleReset = () => { this.setState({ hasError: false, error: undefined, errorInfo: undefined }); if (this.props.onReset) { this.props.onReset(); } }; abstract renderError(): ReactNode; render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return this.renderError(); } return this.props.children; } } /** * Error boundary for API operations * * Catches errors during Kubernetes API calls and provides * guidance for troubleshooting connectivity issues. */ export class ApiErrorBoundary extends BaseErrorBoundary { renderError() { return ( } action={ } > API Communication Error Failed to communicate with the Kubernetes API or Sealed Secrets controller. Please verify:
  • Kubernetes cluster is accessible
  • Sealed Secrets controller is running
  • Controller configuration is correct (name, namespace, port)
  • Network connectivity to the cluster
{this.state.error && ( {(() => { try { const msg = this.state.error.message || this.state.error.toString(); return `Error: ${String(msg)}`; } catch (e) { return 'Error: [Unable to display error message]'; } })()} )}
); } } /** * Generic error boundary for general component errors * * Provides a fallback UI when components encounter unexpected errors. */ export class GenericErrorBoundary extends BaseErrorBoundary { renderError() { return ( } action={ } > Something Went Wrong An unexpected error occurred. Please try reloading the page or contact your administrator if the problem persists. {this.state.error && ( {(() => { try { const msg = this.state.error.message || this.state.error.toString(); return `Error: ${String(msg)}`; } catch (e) { return 'Error: [Unable to display error message]'; } })()} )} ); } }