Files
wzdj/app/admin/screen/_components/error-boundary.tsx

38 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client"
import { useEffect } from "react"
import { Button } from "@/components/ui/button"
import { AlertCircle } from "lucide-react"
export default function ErrorBoundary({
error,
reset,
}: {
error: Error & { digest?: string }
reset: () => void
}) {
useEffect(() => {
// 可以在这里添加错误日志上报
console.error("Error:", error)
}, [error])
// 确保 error 存在且是一个对象
const errorMessage = error?.message || "未知错误"
const errorDigest = error?.digest || null
return (
<div className="flex min-h-[400px] flex-col items-center justify-center rounded-md border border-red-100 bg-red-50 p-8">
<div className="flex h-12 w-12 items-center justify-center rounded-full bg-red-100">
<AlertCircle className="h-6 w-6 text-red-600" />
</div>
<h2 className="mt-4 text-lg font-semibold text-red-600"></h2>
<p className="mt-2 text-sm text-slate-600"></p>
<p className="mt-1 text-sm text-slate-500">{errorMessage}</p>
{errorDigest && <p className="mt-2 text-xs text-slate-500">: {errorDigest}</p>}
<Button onClick={reset} className="mt-4 bg-red-600 text-white hover:bg-red-700">
</Button>
</div>
)
}