From 50522bf4c647f56a151764fff9c81364c3f0a1e0 Mon Sep 17 00:00:00 2001 From: Xavier Desoindre Date: Wed, 13 May 2026 18:45:56 +0200 Subject: [PATCH] fix: retry notion getter --- src/components/Notion/utils.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/Notion/utils.ts b/src/components/Notion/utils.ts index e3e645424..b647c41b4 100644 --- a/src/components/Notion/utils.ts +++ b/src/components/Notion/utils.ts @@ -3,11 +3,29 @@ import { NotionAPI } from 'notion-client' import { getRevalidate } from 'utils/revalidate' const notion = new NotionAPI() + +const getNotionPageWithRetry = async (id: string, retries = 3) => { + try { + return await notion.getPage(id) + } catch (e) { + if (retries > 0) { + const error = e as { response?: { status?: number; headers?: Headers } } + const status = error.response?.status + if (status === 429) { + const retryAfterHeader = error.response?.headers?.get('retry-after') + const delay = retryAfterHeader ? parseFloat(retryAfterHeader) * 1000 : 5000 + await new Promise((resolve) => setTimeout(resolve, delay)) + return getNotionPageWithRetry(id, retries - 1) + } + } + throw e + } +} + export const getNotionContentProps = unstable_cache( async (id: string) => { try { - const result = await notion.getPage(id) - return result + return await getNotionPageWithRetry(id) } catch (e) { console.error('Unable to get content from Notion', e) return undefined