diff --git a/dist/lib/rest/RequestHandler.js b/dist/lib/rest/RequestHandler.js index 7bc68f1aa1878a545f150e78eac7b43155432824..b7d793c6827d704f8d67c070ecae224d61c3a330 100644 --- a/dist/lib/rest/RequestHandler.js +++ b/dist/lib/rest/RequestHandler.js @@ -107,6 +107,7 @@ class RequestHandler { return new Promise((resolve, reject) => { async function attempt(cb) { const headers = options.headers ?? {}; + let timeout; try { if (typeof options.auth === "string") { headers.Authorization = options.auth; @@ -156,7 +157,6 @@ class RequestHandler { const url = `${this.options.baseURL}${options.path}${options.query && Array.from(options.query.keys()).length !== 0 ? `?${options.query.toString()}` : ""}`; let latency = Date.now(); const controller = new AbortController(); - let timeout; if (this.options.requestTimeout > 0 && this.options.requestTimeout !== Infinity) { timeout = setTimeout(() => controller.abort(), this.options.requestTimeout); } @@ -300,10 +300,9 @@ class RequestHandler { resolve(resBody); } catch (err) { + if (timeout) clearTimeout(timeout); cb(); - if (err instanceof Error && err.constructor.name === "DOMException" && err.name === "AbortError") { - reject(new Error(`Request Timed Out (>${this.options.requestTimeout}ms) on ${options.method} ${options.path}`)); - } + reject(err); this._manager.client.emit("error", err); } }