"use client"; import React from "react"; import {Button} from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; interface ErrorBoundaryState { hasError: boolean; error: Error | null; errorInfo: React.ErrorInfo | null; } interface ErrorBoundaryProps { children: React.ReactNode; fallback?: React.ComponentType<{ error: Error; reset: () => void }>; } export class ErrorBoundary extends React.Component< ErrorBoundaryProps, ErrorBoundaryState > { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false, error: null, errorInfo: null, }; } static getDerivedStateFromError(error: Error): Partial { return { hasError: true, error, }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error("ErrorBoundary caught an error:", error, errorInfo); this.setState({ error, errorInfo, }); } handleReset = () => { this.setState({ hasError: false, error: null, errorInfo: null, }); }; render() { if (this.state.hasError) { if (this.props.fallback) { const FallbackComponent = this.props.fallback; return ( ); } return ( ); } return this.props.children; } } interface ErrorDialogProps { error: Error | null; onReset: () => void; open: boolean; } function ErrorDialog({error, onReset, open}: ErrorDialogProps) { return ( { }}> Ein Fehler ist aufgetreten Es ist ein unerwarteter Fehler aufgetreten. Bitte versuchen Sie es erneut. {error && (

{error.message}

)}
); } // Hook for handling async errors export function useErrorHandler() { return React.useCallback((error: unknown) => { console.error("Async error caught:", error); }, []); }