From a3b3e9e0beca315ff780db8aad697389aa2a0199 Mon Sep 17 00:00:00 2001 From: Hemachandar <132386067+hmacr@users.noreply.github.com> Date: Thu, 19 Jun 2025 02:09:58 +0530 Subject: [PATCH] Use `Retry-After` header for Notion rate-limit retries (#9467) --- plugins/notion/server/notion.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/notion/server/notion.ts b/plugins/notion/server/notion.ts index 143bce65df..ba044e69e6 100644 --- a/plugins/notion/server/notion.ts +++ b/plugins/notion/server/notion.ts @@ -107,7 +107,11 @@ export class NotionClient { ) { if (retries < this.maxRetries) { retries++; - const delay = this.retryDelay * retries; + const headers = error.headers as Record; + const retryAfter = headers["Retry-After"] + ? parseInt(headers["Retry-After"], 10) * 1000 // Convert seconds to milliseconds + : undefined; + const delay = retryAfter ?? this.retryDelay * retries; Logger.info( "task", `Notion API rate limit hit, retrying in ${delay}ms (retry ${retries}/${this.maxRetries})`