Skip to content

Commit

Permalink
Improve v8 ratelimit handling (abalabahaha#1256)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsian03 committed Oct 10, 2021
1 parent 4611a58 commit 33818b7
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions lib/rest/RequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,7 @@ class RequestHandler {

this.ratelimits[route].remaining = resp.headers["x-ratelimit-remaining"] === undefined ? 1 : +resp.headers["x-ratelimit-remaining"] || 0;

let retryAfter = parseInt(resp.headers["retry-after"]);
// Discord breaks RFC here, using milliseconds instead of seconds (╯°□°)╯︵ ┻━┻
// This is the unofficial Discord dev-recommended way of detecting that
if(retryAfter && (typeof resp.headers["via"] !== "string" || !resp.headers["via"].includes("1.1 google"))) {
retryAfter *= 1000;
if(retryAfter >= 1000 * 1000) {
this._client.emit("warn", `Excessive Retry-After interval detected (Retry-After: ${resp.headers["retry-after"]} * 1000, Via: ${resp.headers["via"]})`);
}
}
const retryAfter = parseInt(resp.headers["x-ratelimit-reset-after"] || resp.headers["retry-after"]) * 1000;
if(retryAfter >= 0) {
if(resp.headers["x-ratelimit-global"]) {
this.globalBlock = true;
Expand Down

0 comments on commit 33818b7

Please sign in to comment.