From 03524483810dcc933a5c27204fc0c16d0c2ad574 Mon Sep 17 00:00:00 2001 From: Liuweiqing <121866954+14790897@users.noreply.github.com> Date: Mon, 22 Jan 2024 22:54:50 +0800 Subject: [PATCH] chore: error handler --- .vscode/settings.json | 3 ++- app/1global-error.tsx | 30 ++++++++++++++++++++++++++++++ app/page.tsx | 5 ++++- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 app/1global-error.tsx diff --git a/.vscode/settings.json b/.vscode/settings.json index 281a65b..2cc323d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,5 +14,6 @@ "username": "root", "password": "123456" } - ] + ], + "commentTranslate.targetLanguage": "zh-CN" } \ No newline at end of file diff --git a/app/1global-error.tsx b/app/1global-error.tsx new file mode 100644 index 0000000..9440da8 --- /dev/null +++ b/app/1global-error.tsx @@ -0,0 +1,30 @@ +"use client"; // Error components must be Client Components + +import { useEffect } from "react"; + +export default function Error({ + error, + reset, +}: { + error: Error & { digest?: string }; + reset: () => void; +}) { + useEffect(() => { + // Log the error to an error reporting service + console.error(error); + }, [error]); + + return ( +
+

Something went wrong!

+ +
+ ); +} diff --git a/app/page.tsx b/app/page.tsx index 47c9710..52d3fcb 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -10,6 +10,8 @@ import QuillWrapper from "./QuillWrapper"; // import TinyEditor from "../components/TinyEditor"; // import SEditor from "../components/SlateEditor"; import SettingsLink from "@/components/SettingsLink"; +import { ErrorBoundary } from "next/dist/client/components/error-boundary"; +import Error from "@/app/global-error"; export default async function Index() { const cookieStore = cookies(); @@ -35,8 +37,9 @@ export default async function Index() { - + {/* }> */} + {/* */}