Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(RequestHandler): emit more info when a rate limit was hit #5801

Merged
merged 2 commits into from Jun 10, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/rest/RequestHandler.js
Expand Up @@ -5,7 +5,7 @@ const DiscordAPIError = require('./DiscordAPIError');
const HTTPError = require('./HTTPError');
const RateLimitError = require('./RateLimitError');
const {
Events: { RATE_LIMIT, INVALID_REQUEST_WARNING },
Events: { DEBUG, RATE_LIMIT, INVALID_REQUEST_WARNING },
} = require('../util/Constants');
const Util = require('../util/Util');

Expand Down Expand Up @@ -255,9 +255,6 @@ class RequestHandler {
if (res.status >= 400 && res.status < 500) {
// Handle ratelimited requests
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;
let limit, timeout;
if (isGlobal) {
Expand All @@ -269,6 +266,19 @@ class RequestHandler {
limit = this.limit;
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` : false}`,
SpaceEEC marked this conversation as resolved.
Show resolved Hide resolved
);

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
Expand Down