From 8e2ece75261e8cd2e0544fa7b490e08ed4b2e324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Tue, 14 Feb 2023 10:07:58 -0700 Subject: [PATCH] Prevent timeouts when cache fails (#7095) Return empty cache instead of failing Keeping console errors --- .../pages/[user]/calendar-cache/[month].tsx | 29 ++++++++++++++----- apps/web/pages/api/trpc/[trpc].ts | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/apps/web/pages/[user]/calendar-cache/[month].tsx b/apps/web/pages/[user]/calendar-cache/[month].tsx index 40badfe363878e..423eedc054588e 100644 --- a/apps/web/pages/[user]/calendar-cache/[month].tsx +++ b/apps/web/pages/[user]/calendar-cache/[month].tsx @@ -33,13 +33,28 @@ export const getStaticProps: GetStaticProps< dayjs(month, "YYYY-MM").isSame(dayjs(), "month") ? dayjs() : dayjs(month, "YYYY-MM") ).startOf("day"); const endDate = startDate.endOf("month"); - const results = user?.credentials - ? await getCachedResults(user?.credentials, startDate.format(), endDate.format(), user?.selectedCalendars) - : []; - return { - props: { results, date: new Date().toISOString() }, - revalidate: 1, - }; + try { + const results = user?.credentials + ? await getCachedResults( + user?.credentials, + startDate.format(), + endDate.format(), + user?.selectedCalendars + ) + : []; + return { + props: { results, date: new Date().toISOString() }, + revalidate: 1, + }; + } catch (error) { + let message = "Unknown error while fetching calendarÆ’"; + if (error instanceof Error) message = error.message; + console.error(error, message); + return { + props: { results: [], date: new Date().toISOString(), message }, + revalidate: 1, + }; + } }; export const getStaticPaths: GetStaticPaths = () => { diff --git a/apps/web/pages/api/trpc/[trpc].ts b/apps/web/pages/api/trpc/[trpc].ts index af7802e3dcba78..81a1e4598d0d86 100644 --- a/apps/web/pages/api/trpc/[trpc].ts +++ b/apps/web/pages/api/trpc/[trpc].ts @@ -64,7 +64,7 @@ export default trpcNext.createNextApiHandler({ "viewer.public.session": `no-cache`, "viewer.public.i18n": `no-cache`, // Revalidation time here should be 1 second, per https://github.com/calcom/cal.com/pull/6823#issuecomment-1423215321 - "viewer.public.slots.getSchedule": `max-age=0, s-maxage=1`, + "viewer.public.slots.getSchedule": `no-cache`, // FIXME } as const; // Find which element above is an exact match for this group of paths