"use client" import React, { type ErrorInfo } from "react" import { Card } from "@/components/ui/card" import { Button } from "@/components/ui/button" interface ErrorBoundaryProps { children: React.ReactNode } interface ErrorBoundaryState { hasError: boolean error?: Error } class ErrorBoundary extends React.Component { constructor(props: ErrorBoundaryProps) { super(props) this.state = { hasError: false } } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error } } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error("Uncaught error:", error, errorInfo) } render() { if (this.state.hasError) { return (

出错了

抱歉,应用程序遇到了一个错误。

{this.state.error?.message}

) } return this.props.children } } export default ErrorBoundary