Skip to content

Commit

Permalink
feat: add debug logging for rate limit status
Browse files Browse the repository at this point in the history
  • Loading branch information
thislooksfun committed Apr 10, 2022
1 parent 8f56359 commit 7ef9e83
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/gateway/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { makeDebug } from "../helper/debug";

// #region debug logging
const debug = {
general: makeDebug("gateway"),
request: makeDebug("gateway:request"),
response: makeDebug("gateway:response"),
};
Expand Down Expand Up @@ -216,6 +217,11 @@ export abstract class Gateway {
const remain = Number.parseInt(headers["x-ratelimit-remaining"] as string);
const reset = Number.parseInt(headers["x-ratelimit-reset"] as string);
this.rateLimit = { remaining: remain, reset: Date.now() + reset * 1000 };
debug.general(
"Updated ratelimit: %d requests remaining, resets at %s",
this.rateLimit.remaining,
new Date(this.rateLimit.reset)
);
return response;
}
}

0 comments on commit 7ef9e83

Please sign in to comment.