From fc6f5674d9cacff4745acb35a9fd2fc12ca9a604 Mon Sep 17 00:00:00 2001 From: rowthan <12638456+rowthan@users.noreply.github.com> Date: Sat, 20 Jul 2024 08:37:33 +0800 Subject: [PATCH] build: catch init error --- apps/web/pages/gift.tsx | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/web/pages/gift.tsx b/apps/web/pages/gift.tsx index 5cf56743..da800877 100644 --- a/apps/web/pages/gift.tsx +++ b/apps/web/pages/gift.tsx @@ -25,23 +25,26 @@ enum ReceiveStatus { type UserForm = { uid?: number; email?: string } export async function getStaticProps() { - const keys = Object.keys(demoGiftDetail).join(',') - const data = await fetch( - `${process.env.API_HOST}/api/graph/book?query=query{gifts{${keys}}}`, - { - headers: { - token: 'system_20231212', - }, - } - ).then(function (res) { - return res.json() - }) - - console.log(data, 'static props') - + const keys = Object.keys(demoGiftDetail).join(','); + const gifts = []; + try{ + const data = await fetch( + `${process.env.API_HOST}/api/graph/book?query=query{gifts{${keys}}}`, + { + headers: { + token: 'system_20231212', + }, + } + ).then(function (res) { + return res.json() + }) + gifts.push(...data?.data?.gifts || []) + }catch (e) { + console.warn('init gifts error') + } return { props: { - gifts: data?.data?.gifts || [], + gifts: gifts || [], }, } }