Skip to content

Commit

Permalink
Add requestTimeout Client option (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
LJNeon authored and abalabahaha committed Jul 29, 2018
1 parent 94019f1 commit 0a1ea97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/Client.js
Expand Up @@ -73,12 +73,13 @@ class Client extends EventEmitter {
* @arg {Boolean} [options.getAllUsers=false] Get all the users in every guild. Ready time will be severely delayed
* @arg {Number} [options.guildCreateTimeout=2000] How long in milliseconds to wait for a GUILD_CREATE before "ready" is fired. Increase this value if you notice missing guilds
* @arg {Number} [options.largeThreshold=250] The maximum number of offline users per guild during initial guild data transmission
* @arg {Number} [options.latencyThreshold=4000] The average request latency at which Eris will start emitting latency errors
* @arg {Number} [options.latencyThreshold=30000] The average request latency at which Eris will start emitting latency errors
* @arg {Number} [options.lastShardID=options.maxShards - 1] The ID of the last shard to run for this client
* @arg {Number|String} [options.maxShards=1] The total number of shards you want to run. If "auto" Eris will use Discord's recommended shard count.
* @arg {Number} [options.messageLimit=100] The maximum size of a channel message cache
* @arg {Boolean} [options.opusOnly=false] Whether to suppress the node-opus not found error or not
* @arg {Number} [options.ratelimiterOffset=0] A number of milliseconds to offset the ratelimit timing calculations by
* @arg {Number} [options.requestTimeout=15000] A number of milliseconds before requests are considered timed out
* @arg {Boolean} [options.restMode=false] Whether to enable getting objects over REST. This should only be enabled if you are not connecting to the gateway. Bot tokens must be prefixed manually in REST mode
* @arg {Boolean} [options.seedVoiceConnections=false] Whether to populate bot.voiceConnections with existing connections the bot account has during startup. Note that this will disconnect connections from other bot sessions
* @arg {String} [options.defaultImageFormat="jpg"] The default format to provide user avatars, guild icons, and group icons in. Can be "jpg", "png", "gif", or "webp"
Expand All @@ -105,6 +106,7 @@ class Client extends EventEmitter {
messageLimit: 100,
opusOnly: false,
ratelimiterOffset: 0,
requestTimeout: 15000,
restMode: false,
seedVoiceConnections: false,
ws: {}
Expand Down
5 changes: 3 additions & 2 deletions lib/rest/RequestHandler.js
Expand Up @@ -17,6 +17,7 @@ class RequestHandler {
this.baseURL = Endpoints.BASE_URL;
this.userAgent = `DiscordBot (https://github.com/abalabahaha/eris, ${require("../../package.json").version})`;
this.ratelimits = {};
this.requestTimeout = client.options.requestTimeout;
this.latencyRef = {
latency: 500,
offset: client.options.ratelimiterOffset,
Expand Down Expand Up @@ -303,8 +304,8 @@ class RequestHandler {
});
});

req.setTimeout(15000, function() {
reqError = new Error(`Request timed out (>15000ms) on ${method} ${url}`);
req.setTimeout(this.requestTimeout, function() {
reqError = new Error(`Request timed out (>${this.requestTimeout}ms) on ${method} ${url}`);
req.abort();
});

Expand Down

0 comments on commit 0a1ea97

Please sign in to comment.