Handling rating limit of Discord Webhook API

This commit is contained in:
neomaking 2019-10-20 22:14:42 +02:00
parent 027ce90f89
commit f2af8d706d

View file

@ -152,12 +152,15 @@ export class DiscordWebhook implements INodeType {
responseData = await this.helpers.request(options); responseData = await this.helpers.request(options);
} catch (error) { } catch (error) {
if (error.statusCode === 429) { if (error.statusCode === 429) {
// Return API Rate Limit error // Waiting rating limit
throw new Error(`You are rate limited, please retry in ${error.response.body.retry_after} ms.`); 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); returnData.push(responseData as IDataObject);