From 28dfe8c61a66b24832476fa3b45b011712a44740 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Sun, 4 Sep 2022 16:28:52 +0200 Subject: [PATCH] fix: cloudflare uses seconds for `retry-after` --- lib/webhook.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/webhook.ts b/lib/webhook.ts index f6de1f0..82dbe16 100644 --- a/lib/webhook.ts +++ b/lib/webhook.ts @@ -29,7 +29,13 @@ export async function sendWebhook( // should always exist, even for cf bans, but checking anyway if (reset === null) break; - const resetms = parseFloat(reset); + // parse retry delay + let resetms = parseFloat(reset); + if (!res.headers.has("via")) { + // if there's no `via` header, this is likely a cf ban, which uses seconds instead of milliseconds + resetms *= 1000; + } + // if we'd wait longer than the configured limit, just return the 429 if (resetms > config.maxWebhookRetryMs) { log.warning(