From a6995cc04ab87baf50a8f685ce7b0e6322d5e998 Mon Sep 17 00:00:00 2001 From: rowthan <12638456+rowthan@users.noreply.github.com> Date: Sat, 27 Jul 2024 19:09:41 +0800 Subject: [PATCH] feat: revalidate vip page --- apps/web/pages/vip.tsx | 3 ++- apps/web/utils/Error.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 apps/web/utils/Error.ts diff --git a/apps/web/pages/vip.tsx b/apps/web/pages/vip.tsx index d1a69a8a..5a9d420f 100644 --- a/apps/web/pages/vip.tsx +++ b/apps/web/pages/vip.tsx @@ -22,7 +22,8 @@ export async function getStaticProps() { props: { doc: res.props, plans: plans - } + }, + revalidate: 60 * 60 * 4, // 单位 秒 }; } diff --git a/apps/web/utils/Error.ts b/apps/web/utils/Error.ts new file mode 100644 index 00000000..7c4f3f72 --- /dev/null +++ b/apps/web/utils/Error.ts @@ -0,0 +1,26 @@ +class PagenoteError extends Error { + private readonly data: any; + constructor(message:string, data:any) { + super(message); // 调用父类的构造函数 + this.name = this.constructor.name; // 设置错误名称 + this.message = message; // 错误信息 + this.data = data; + + // 错误堆栈信息 + if (Error.captureStackTrace) { + Error.captureStackTrace(this, this.constructor); + } else { + this.stack = (new Error()).stack; + } + + // 执行自定义程序,例如上报服务器 + this.reportError(); + } + + // 自定义方法,用于上报错误 + reportError() { + const { data, message } = this; + console.log(`上报错误: ${message}, 数据: ${JSON.stringify(data)}`); + + } +}