From 0931fe103d37f02e4effacc2d8bcd8612cc2f905 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Tue, 22 Aug 2023 21:22:18 +0200 Subject: [PATCH] Wait some time before retrying an OpenAI request OpenAI recommended prectice is to wait some time before retrying the request that ended with http 5xx code the bot was not doing that before, now it does this might fix some issues when we were retrying the request too fast --- src/execution.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/execution.ts b/src/execution.ts index fec4160..8879b00 100644 --- a/src/execution.ts +++ b/src/execution.ts @@ -349,6 +349,7 @@ async function executeFromQueue(channel: string) { else errorText = ""; if (Axios.isAxiosError(e) && e.code?.match(/^5..$/) && channelQueue.tries < 3) { channelQueue.tries++; + await new Promise(r => setTimeout(r, 2000)); // pause for 2 seconds before retrying return executeFromQueue(channel); }