mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
feat: add ClientOptions#retryLimit (#2805)
* feat: add ClientOptions#retryLimit * hydra needs to learn how to code right * a default would probably help * move incrementor & update comment * clarify docs on Infinity
This commit is contained in:
@@ -436,6 +436,9 @@ class Client extends BaseClient {
|
||||
if (!(options.disabledEvents instanceof Array)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'disabledEvents', 'an Array');
|
||||
}
|
||||
if (typeof options.retryLimit !== 'number' || isNaN(options.retryLimit)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'retryLimit', 'a number');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ class RESTManager {
|
||||
request: apiRequest,
|
||||
resolve,
|
||||
reject,
|
||||
retries: 0,
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -150,13 +150,13 @@ class RequestHandler {
|
||||
await Util.delayFor(this.retryAfter);
|
||||
return this.run();
|
||||
} else if (res.status >= 500 && res.status < 600) {
|
||||
// Retry once for possible serverside issues
|
||||
if (item.retried) {
|
||||
// Retry the specified number of times for possible serverside issues
|
||||
if (item.retries === this.manager.client.options.retryLimit) {
|
||||
return reject(
|
||||
new HTTPError(res.statusText, res.constructor.name, res.status, item.request.method, request.route)
|
||||
);
|
||||
} else {
|
||||
item.retried = true;
|
||||
item.retries++;
|
||||
this.queue.unshift(item);
|
||||
return this.run();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ const browser = exports.browser = typeof window !== 'undefined';
|
||||
* requests (higher values will reduce rate-limiting errors on bad connections)
|
||||
* @property {number} [restSweepInterval=60] How frequently to delete inactive request buckets, in seconds
|
||||
* (or 0 for never)
|
||||
* @property {number} [retryLimit=1] How many times to retry on 5XX errors (Infinity for indefinite amount of retries)
|
||||
* @property {PresenceData} [presence] Presence data to use upon login
|
||||
* @property {WSEventType[]} [disabledEvents] An array of disabled websocket events. Events in this array will not be
|
||||
* processed, potentially resulting in performance improvements for larger bots. Only disable events you are
|
||||
@@ -42,6 +43,7 @@ exports.DefaultOptions = {
|
||||
disableEveryone: false,
|
||||
restWsBridgeTimeout: 5000,
|
||||
disabledEvents: [],
|
||||
retryLimit: 1,
|
||||
restTimeOffset: 500,
|
||||
restSweepInterval: 60,
|
||||
presence: {},
|
||||
|
||||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@@ -1557,6 +1557,7 @@ declare module 'discord.js' {
|
||||
disableEveryone?: boolean;
|
||||
restWsBridgeTimeout?: number;
|
||||
restTimeOffset?: number;
|
||||
retryLimit?: number,
|
||||
disabledEvents?: WSEventType[];
|
||||
ws?: WebSocketOptions;
|
||||
http?: HTTPOptions;
|
||||
|
||||
Reference in New Issue
Block a user