mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33: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)) {
|
if (!(options.disabledEvents instanceof Array)) {
|
||||||
throw new TypeError('CLIENT_INVALID_OPTION', 'disabledEvents', 'an 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,
|
request: apiRequest,
|
||||||
resolve,
|
resolve,
|
||||||
reject,
|
reject,
|
||||||
|
retries: 0,
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,13 +150,13 @@ class RequestHandler {
|
|||||||
await Util.delayFor(this.retryAfter);
|
await Util.delayFor(this.retryAfter);
|
||||||
return this.run();
|
return this.run();
|
||||||
} else if (res.status >= 500 && res.status < 600) {
|
} else if (res.status >= 500 && res.status < 600) {
|
||||||
// Retry once for possible serverside issues
|
// Retry the specified number of times for possible serverside issues
|
||||||
if (item.retried) {
|
if (item.retries === this.manager.client.options.retryLimit) {
|
||||||
return reject(
|
return reject(
|
||||||
new HTTPError(res.statusText, res.constructor.name, res.status, item.request.method, request.route)
|
new HTTPError(res.statusText, res.constructor.name, res.status, item.request.method, request.route)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
item.retried = true;
|
item.retries++;
|
||||||
this.queue.unshift(item);
|
this.queue.unshift(item);
|
||||||
return this.run();
|
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)
|
* requests (higher values will reduce rate-limiting errors on bad connections)
|
||||||
* @property {number} [restSweepInterval=60] How frequently to delete inactive request buckets, in seconds
|
* @property {number} [restSweepInterval=60] How frequently to delete inactive request buckets, in seconds
|
||||||
* (or 0 for never)
|
* (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 {PresenceData} [presence] Presence data to use upon login
|
||||||
* @property {WSEventType[]} [disabledEvents] An array of disabled websocket events. Events in this array will not be
|
* @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
|
* processed, potentially resulting in performance improvements for larger bots. Only disable events you are
|
||||||
@@ -42,6 +43,7 @@ exports.DefaultOptions = {
|
|||||||
disableEveryone: false,
|
disableEveryone: false,
|
||||||
restWsBridgeTimeout: 5000,
|
restWsBridgeTimeout: 5000,
|
||||||
disabledEvents: [],
|
disabledEvents: [],
|
||||||
|
retryLimit: 1,
|
||||||
restTimeOffset: 500,
|
restTimeOffset: 500,
|
||||||
restSweepInterval: 60,
|
restSweepInterval: 60,
|
||||||
presence: {},
|
presence: {},
|
||||||
|
|||||||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@@ -1557,6 +1557,7 @@ declare module 'discord.js' {
|
|||||||
disableEveryone?: boolean;
|
disableEveryone?: boolean;
|
||||||
restWsBridgeTimeout?: number;
|
restWsBridgeTimeout?: number;
|
||||||
restTimeOffset?: number;
|
restTimeOffset?: number;
|
||||||
|
retryLimit?: number,
|
||||||
disabledEvents?: WSEventType[];
|
disabledEvents?: WSEventType[];
|
||||||
ws?: WebSocketOptions;
|
ws?: WebSocketOptions;
|
||||||
http?: HTTPOptions;
|
http?: HTTPOptions;
|
||||||
|
|||||||
Reference in New Issue
Block a user