Prevent timeouts when cache fails (#7095)

Return empty cache instead of failing

Keeping console errors
This commit is contained in:
Omar López
2023-02-14 10:07:58 -07:00
committed by GitHub
parent b6eca6e083
commit 8e2ece7526
2 changed files with 23 additions and 8 deletions
@@ -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 = () => {
+1 -1
View File
@@ -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