mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
refactor: clean up rate limit handling (#2694)
* refactor: clean up rate limit handling * requested changes * remove request mode option * fix dupe requests * hardcode reaction ratelimits * suggested changes * fix small thing * re-add restTimeOffset * move restTimeOffset a bit * i swear i know english its my native language ok * requested changes * fix: a bit *too* pre-emptive with ratelimits, now less so * fix: dapi error shoudl reject with path * fix: make errors in execute catchable * fix promise return * rebase is hard
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const handlers = require('./handlers');
|
||||
const RequestHandler = require('./RequestHandler');
|
||||
const APIRequest = require('./APIRequest');
|
||||
const routeBuilder = require('./APIRouter');
|
||||
const { Error } = require('../errors');
|
||||
@@ -12,6 +12,7 @@ class RESTManager {
|
||||
this.globallyRateLimited = false;
|
||||
this.tokenPrefix = tokenPrefix;
|
||||
this.versioned = true;
|
||||
this.globalTimeout = null;
|
||||
if (client.options.restSweepInterval > 0) {
|
||||
client.setInterval(() => {
|
||||
this.handlers.sweep(handler => handler._inactive);
|
||||
@@ -41,24 +42,16 @@ class RESTManager {
|
||||
request: apiRequest,
|
||||
resolve,
|
||||
reject,
|
||||
});
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
getRequestHandler() {
|
||||
const method = this.client.options.apiRequestMethod;
|
||||
if (typeof method === 'function') return method;
|
||||
const handler = handlers[method];
|
||||
if (!handler) throw new Error('RATELIMIT_INVALID_METHOD');
|
||||
return handler;
|
||||
}
|
||||
|
||||
request(method, url, options = {}) {
|
||||
const apiRequest = new APIRequest(this, method, url, options);
|
||||
let handler = this.handlers.get(apiRequest.route);
|
||||
|
||||
if (!handler) {
|
||||
handler = new handlers.RequestHandler(this, this.getRequestHandler());
|
||||
handler = new RequestHandler(this);
|
||||
this.handlers.set(apiRequest.route, handler);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user