From 2919331003b4dec1b32d4fac293cb9bb506b9775 Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Wed, 9 Sep 2020 21:53:00 -0700 Subject: [PATCH] Release 1.5.3 for fixed fixed error handling --- index.js | 20 ++++++++++---------- package.json | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index a702b9f..40f5b58 100644 --- a/index.js +++ b/index.js @@ -97,14 +97,7 @@ Region.prototype.get = function() { reqConfig.headers = { [this.config.keyHeader]: this.config.key }; else qs[this.config.keyQueryParam] = this.config.key; - return req(reqConfig).catch(err => { - this.liveRequests--; - if (err.error && 'ETIMEDOUT' === err.error.code && retries < this.config.retries) { // Retry connection timeouts. - retries++; - return fn(); - } - throw new Error('Failed after ' + retries + ' retries due to: ' + err.message); - }).then(res => { + return req(reqConfig).then(res => { this.liveRequests--; rateLimits.forEach(rl => rl.onResponse(res)); if (400 === res.statusCode) @@ -118,6 +111,13 @@ Region.prototype.get = function() { return fn(); } return JSON.parse(res.body); + }, err => { + this.liveRequests--; + if (err.error && 'ETIMEDOUT' === err.error.code && retries < this.config.retries) { // Retry connection timeouts. + retries++; + return fn(); + } + throw new Error('Failed after ' + retries + ' retries due to: ' + err.message); }); }; return Promise.resolve(fn()); @@ -158,8 +158,8 @@ RateLimit.prototype.onResponse = function(res) { } } - let limitHeader = res.headers[this.type.headerLimit]; - let countHeader = res.headers[this.type.headerCount]; + const limitHeader = res.headers[this.type.headerLimit]; + const countHeader = res.headers[this.type.headerCount]; if (this._bucketsNeedUpdate(limitHeader, countHeader)) this.buckets = RateLimit._getBucketsFromHeaders(limitHeader, countHeader); }; diff --git a/package.json b/package.json index f947f88..47a1f10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "teemojs", - "version": "1.5.2", + "version": "1.5.3", "description": "A Fast & Lightweight Riot API Wrapper", "main": "index.js", "scripts": {