mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
Add 429 handling back into Sequential Handler
This commit is contained in:
@@ -45,9 +45,17 @@ module.exports = class SequentialRequestHandler extends RequestHandler {
|
|||||||
this.timeDifference = Date.now() - new Date(res.headers.date).getTime();
|
this.timeDifference = Date.now() - new Date(res.headers.date).getTime();
|
||||||
}
|
}
|
||||||
if (err) {
|
if (err) {
|
||||||
this.waiting = false;
|
if (err.status === 429) {
|
||||||
item.reject(err);
|
setTimeout(() => {
|
||||||
reject(err);
|
this.waiting = false;
|
||||||
|
resolve();
|
||||||
|
}, res.headers['retry-after']);
|
||||||
|
} else {
|
||||||
|
this.queue.shift();
|
||||||
|
this.waiting = false;
|
||||||
|
item.reject(err);
|
||||||
|
resolve(err);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.queue.shift();
|
this.queue.shift();
|
||||||
const data = res && res.body ? res.body : {};
|
const data = res && res.body ? res.body : {};
|
||||||
@@ -56,7 +64,7 @@ module.exports = class SequentialRequestHandler extends RequestHandler {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.waiting = false;
|
this.waiting = false;
|
||||||
resolve(data);
|
resolve(data);
|
||||||
}, (this.requestResetTime - Date.now()) + this.timeDifference + 1000);
|
}, (this.requestResetTime - Date.now()) + this.timeDifference - 1000);
|
||||||
} else {
|
} else {
|
||||||
this.waiting = false;
|
this.waiting = false;
|
||||||
resolve(data);
|
resolve(data);
|
||||||
@@ -74,6 +82,6 @@ module.exports = class SequentialRequestHandler extends RequestHandler {
|
|||||||
this.waiting = true;
|
this.waiting = true;
|
||||||
|
|
||||||
const item = this.queue[0];
|
const item = this.queue[0];
|
||||||
this.execute(item).then(() => this.handle()).catch(console.log);
|
this.execute(item).then(() => this.handle());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user