Skip to content

Commit

Permalink
fix: WebhookClient should handle ratelimits properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Lewdcario committed Aug 21, 2018
1 parent dc8cf08 commit 4ee3cf0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/client/rest/RequestHandlers/Sequential.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ class SequentialRequestHandler extends RequestHandler {
if (err) {
if (err.status === 429) {
this.queue.unshift(item);
this.restManager.client.setTimeout(() => {
this.client.setTimeout(() => {
this.globalLimit = false;
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;
} else if (err.status >= 500 && err.status < 600) {
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 {
item.reject(err.status >= 400 && err.status < 500 ?
new DiscordAPIError(res.request.path, res.body, res.request.method) : err);
Expand Down Expand Up @@ -101,9 +101,9 @@ class SequentialRequestHandler extends RequestHandler {
method: item.request.method,
});
}
this.restManager.client.setTimeout(
this.client.setTimeout(
() => resolve(data),
this.requestResetTime - Date.now() + this.timeDifference + this.restManager.client.options.restTimeOffset
this.requestResetTime - Date.now() + this.timeDifference + this.client.options.restTimeOffset
);
} else {
resolve(data);
Expand Down
4 changes: 3 additions & 1 deletion src/structures/Webhook.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const EventEmitter = require('events');
const path = require('path');
const Util = require('../util/Util');
const Attachment = require('./Attachment');
Expand All @@ -6,8 +7,9 @@ const RichEmbed = require('./RichEmbed');
/**
* Represents a webhook.
*/
class Webhook {
class Webhook extends EventEmitter {
constructor(client, dataOrID, token) {
super();
if (client) {
/**
* The client that instantiated the webhook
Expand Down

0 comments on commit 4ee3cf0

Please # to comment.