From f2af8d706dfe7c52438af6aa2b34d04eb3b84ac8 Mon Sep 17 00:00:00 2001 From: neomaking Date: Sun, 20 Oct 2019 22:14:42 +0200 Subject: [PATCH] Handling rating limit of Discord Webhook API --- .../nodes/DiscordWebhook/DiscordWebhook.node.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/nodes-base/nodes/DiscordWebhook/DiscordWebhook.node.ts b/packages/nodes-base/nodes/DiscordWebhook/DiscordWebhook.node.ts index 0fb5147783..1587b56c07 100644 --- a/packages/nodes-base/nodes/DiscordWebhook/DiscordWebhook.node.ts +++ b/packages/nodes-base/nodes/DiscordWebhook/DiscordWebhook.node.ts @@ -152,12 +152,15 @@ export class DiscordWebhook implements INodeType { responseData = await this.helpers.request(options); } catch (error) { if (error.statusCode === 429) { - // Return API Rate Limit error - throw new Error(`You are rate limited, please retry in ${error.response.body.retry_after} ms.`); + // Waiting rating limit + setTimeout(async () => { + responseData = await this.helpers.request(options) + }, + error.response.body.retry_after); + }else { + // If it's another error code then return the JSON response + throw error; } - - // If it's another error code then return the JSON response - throw error; } returnData.push(responseData as IDataObject);