mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
fix: WebhookClient should handle ratelimits properly
This commit is contained in:
@@ -66,14 +66,14 @@ class SequentialRequestHandler extends RequestHandler {
|
|||||||
if (err) {
|
if (err) {
|
||||||
if (err.status === 429) {
|
if (err.status === 429) {
|
||||||
this.queue.unshift(item);
|
this.queue.unshift(item);
|
||||||
this.restManager.client.setTimeout(() => {
|
this.client.setTimeout(() => {
|
||||||
this.globalLimit = false;
|
this.globalLimit = false;
|
||||||
resolve();
|
resolve();
|
||||||
}, Number(res.headers['retry-after']) + this.restManager.client.options.restTimeOffset);
|
}, Number(res.headers['retry-after']) + this.client.options.restTimeOffset);
|
||||||
if (res.headers['x-ratelimit-global']) this.globalLimit = true;
|
if (res.headers['x-ratelimit-global']) this.globalLimit = true;
|
||||||
} else if (err.status >= 500 && err.status < 600) {
|
} else if (err.status >= 500 && err.status < 600) {
|
||||||
this.queue.unshift(item);
|
this.queue.unshift(item);
|
||||||
this.restManager.client.setTimeout(resolve, 1e3 + this.restManager.client.options.restTimeOffset);
|
this.client.setTimeout(resolve, 1e3 + this.client.options.restTimeOffset);
|
||||||
} else {
|
} else {
|
||||||
item.reject(err.status >= 400 && err.status < 500 ?
|
item.reject(err.status >= 400 && err.status < 500 ?
|
||||||
new DiscordAPIError(res.request.path, res.body, res.request.method) : err);
|
new DiscordAPIError(res.request.path, res.body, res.request.method) : err);
|
||||||
@@ -101,9 +101,9 @@ class SequentialRequestHandler extends RequestHandler {
|
|||||||
method: item.request.method,
|
method: item.request.method,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.restManager.client.setTimeout(
|
this.client.setTimeout(
|
||||||
() => resolve(data),
|
() => resolve(data),
|
||||||
this.requestResetTime - Date.now() + this.timeDifference + this.restManager.client.options.restTimeOffset
|
this.requestResetTime - Date.now() + this.timeDifference + this.client.options.restTimeOffset
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
resolve(data);
|
resolve(data);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const EventEmitter = require('events');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const Util = require('../util/Util');
|
const Util = require('../util/Util');
|
||||||
const Attachment = require('./Attachment');
|
const Attachment = require('./Attachment');
|
||||||
@@ -6,8 +7,9 @@ const RichEmbed = require('./RichEmbed');
|
|||||||
/**
|
/**
|
||||||
* Represents a webhook.
|
* Represents a webhook.
|
||||||
*/
|
*/
|
||||||
class Webhook {
|
class Webhook extends EventEmitter {
|
||||||
constructor(client, dataOrID, token) {
|
constructor(client, dataOrID, token) {
|
||||||
|
super();
|
||||||
if (client) {
|
if (client) {
|
||||||
/**
|
/**
|
||||||
* The client that instantiated the webhook
|
* The client that instantiated the webhook
|
||||||
|
|||||||
Reference in New Issue
Block a user