Skip to content

Commit

Permalink
Revert "feat: abort Requests that takes a lot of time to resolve (dis…
Browse files Browse the repository at this point in the history
…cordjs#3327)"

This reverts commit 895bf54.
  • Loading branch information
samsamson33 committed Feb 27, 2020
1 parent b0eee50 commit 4d111ad
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 12 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -35,7 +35,6 @@
"runkitExampleFilename": "./docs/examples/ping.js",
"unpkg": "./webpack/discord.min.js",
"dependencies": {
"abort-controller": "^3.0.0",
"form-data": "^2.3.3",
"node-fetch": "^2.3.0",
"pako": "^1.0.8",
Expand Down
3 changes: 0 additions & 3 deletions src/client/Client.js
Expand Up @@ -392,9 +392,6 @@ class Client extends BaseClient {
if (typeof options.restWsBridgeTimeout !== 'number' || isNaN(options.restWsBridgeTimeout)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'restWsBridgeTimeout', 'a number');
}
if (typeof options.restRequestTimeout !== 'number' || isNaN(options.restRequestTimeout)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'restRequestTimeout', 'a number');
}
if (typeof options.restSweepInterval !== 'number' || isNaN(options.restSweepInterval)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'restSweepInterval', 'a number');
}
Expand Down
6 changes: 1 addition & 5 deletions src/rest/APIRequest.js
Expand Up @@ -4,7 +4,6 @@ const FormData = require('form-data');
const https = require('https');
const { browser, UserAgent } = require('../util/Constants');
const fetch = require('node-fetch');
const AbortController = require('abort-controller');

if (https.Agent) var agent = new https.Agent({ keepAlive: true });

Expand Down Expand Up @@ -47,15 +46,12 @@ class APIRequest {
headers['Content-Type'] = 'application/json';
}

const controller = new AbortController();
const timeout = this.client.setTimeout(() => controller.abort(), this.client.options.restRequestTimeout);
return fetch(url, {
method: this.method,
headers,
agent,
body,
signal: controller.signal,
}).finally(() => this.client.clearTimeout(timeout));
});
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/util/Constants.js
Expand Up @@ -28,7 +28,6 @@ const browser = exports.browser = typeof window !== 'undefined';
* corresponding websocket events
* @property {number} [restTimeOffset=500] Extra time in millseconds to wait before continuing to make REST
* requests (higher values will reduce rate-limiting errors on bad connections)
* @property {number} [restRequestTimeout=15000] Time to wait before cancelling a REST request
* @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)
Expand All @@ -51,7 +50,6 @@ exports.DefaultOptions = {
partials: [],
restWsBridgeTimeout: 5000,
disabledEvents: [],
restRequestTimeout: 15000,
retryLimit: 1,
restTimeOffset: 500,
restSweepInterval: 60,
Expand Down
1 change: 0 additions & 1 deletion typings/index.d.ts
Expand Up @@ -2018,7 +2018,6 @@ declare module 'discord.js' {
partials?: PartialTypes[];
restWsBridgeTimeout?: number;
restTimeOffset?: number;
restRequestTimeout?: number;
restSweepInterval?: number;
retryLimit?: number;
presence?: PresenceData;
Expand Down

0 comments on commit 4d111ad

Please sign in to comment.