mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Added option to count rate limits as errors
`options.rate_limit_as_error`
This commit is contained in:
@@ -46,6 +46,7 @@ var Client = (function (_EventEmitter) {
|
||||
this.options = options || {};
|
||||
this.options.compress = options.compress || true;
|
||||
this.options.revive = options.revive || false;
|
||||
this.options.rate_limit_as_error = options.rate_limit_as_error || false;
|
||||
this.internal = new _InternalClient2["default"](this);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,11 +133,11 @@ var InternalClient = (function () {
|
||||
ret.end(function (error, data) {
|
||||
if (error) {
|
||||
error.response.error.status = 429;
|
||||
if (error.response && error.response.error && error.response.error.status && error.response.error.status === 429) {
|
||||
if (!_this.client.options.rate_limit_as_error && error.response && error.response.error && error.response.error.status && error.response.error.status === 429) {
|
||||
|
||||
if (data.headers["retry-after"] || data.headers["Retry-After"]) {
|
||||
var toWait = data.headers["retry-after"] || data.headers["Retry-After"];
|
||||
toWait = parseInt(toWait);
|
||||
console.log("waiting for", toWait);
|
||||
setTimeout(function () {
|
||||
_this.apiRequest.apply(_this, _arguments).then(resolve)["catch"](reject);
|
||||
}, toWait);
|
||||
|
||||
@@ -21,6 +21,7 @@ export default class Client extends EventEmitter {
|
||||
this.options = options || {};
|
||||
this.options.compress = options.compress || true;
|
||||
this.options.revive = options.revive || false;
|
||||
this.options.rate_limit_as_error = options.rate_limit_as_error || false;
|
||||
this.internal = new InternalClient(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,13 @@ export default class InternalClient {
|
||||
ret.end((error, data) => {
|
||||
if (error) {
|
||||
error.response.error.status = 429;
|
||||
if (error.response && error.response.error && error.response.error.status && error.response.error.status === 429) {
|
||||
if (!this.client.options.rate_limit_as_error &&
|
||||
error.response &&
|
||||
error.response.error &&
|
||||
error.response.error.status
|
||||
&& error.response.error.status === 429
|
||||
) {
|
||||
|
||||
if(data.headers["retry-after"] || data.headers["Retry-After"]){
|
||||
var toWait = data.headers["retry-after"] || data.headers["Retry-After"];
|
||||
toWait = parseInt(toWait);
|
||||
@@ -76,6 +82,7 @@ export default class InternalClient {
|
||||
} else {
|
||||
return reject(error);
|
||||
}
|
||||
|
||||
} else {
|
||||
return reject(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user