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 ( +