mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
feat(RequestHandler): emit more info when a rate limit was hit (#5801)
* feat(RequestHandler): emit more info when a rate limit was hit * emit 'None' when no sublimit was hit Co-authored-by: Antonio Román <kyradiscord@gmail.com> Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@ const DiscordAPIError = require('./DiscordAPIError');
|
|||||||
const HTTPError = require('./HTTPError');
|
const HTTPError = require('./HTTPError');
|
||||||
const RateLimitError = require('./RateLimitError');
|
const RateLimitError = require('./RateLimitError');
|
||||||
const {
|
const {
|
||||||
Events: { RATE_LIMIT, INVALID_REQUEST_WARNING },
|
Events: { DEBUG, RATE_LIMIT, INVALID_REQUEST_WARNING },
|
||||||
} = require('../util/Constants');
|
} = require('../util/Constants');
|
||||||
const Util = require('../util/Util');
|
const Util = require('../util/Util');
|
||||||
|
|
||||||
@@ -255,9 +255,6 @@ class RequestHandler {
|
|||||||
if (res.status >= 400 && res.status < 500) {
|
if (res.status >= 400 && res.status < 500) {
|
||||||
// Handle ratelimited requests
|
// Handle ratelimited requests
|
||||||
if (res.status === 429) {
|
if (res.status === 429) {
|
||||||
// A ratelimit was hit - this should never happen
|
|
||||||
this.manager.client.emit('debug', `429 hit on route ${request.route}${sublimitTimeout ? ' for sublimit' : ''}`);
|
|
||||||
|
|
||||||
const isGlobal = this.globalLimited;
|
const isGlobal = this.globalLimited;
|
||||||
let limit, timeout;
|
let limit, timeout;
|
||||||
if (isGlobal) {
|
if (isGlobal) {
|
||||||
@@ -269,6 +266,19 @@ class RequestHandler {
|
|||||||
limit = this.limit;
|
limit = this.limit;
|
||||||
timeout = this.reset + this.manager.client.options.restTimeOffset - Date.now();
|
timeout = this.reset + this.manager.client.options.restTimeOffset - Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.manager.client.emit(
|
||||||
|
DEBUG,
|
||||||
|
`Hit a 429 while executing a request.
|
||||||
|
Global : ${isGlobal}
|
||||||
|
Method : ${request.method}
|
||||||
|
Path : ${request.path}
|
||||||
|
Route : ${request.route}
|
||||||
|
Limit : ${limit}
|
||||||
|
Timeout : ${timeout}ms
|
||||||
|
Sublimit: ${sublimitTimeout ? `${sublimitTimeout}ms` : 'None'}`,
|
||||||
|
);
|
||||||
|
|
||||||
await this.onRateLimit(request, limit, timeout, isGlobal);
|
await this.onRateLimit(request, limit, timeout, isGlobal);
|
||||||
|
|
||||||
// If caused by a sublimit, wait it out here so other requests on the route can be handled
|
// If caused by a sublimit, wait it out here so other requests on the route can be handled
|
||||||
|
|||||||
Reference in New Issue
Block a user