Skip to content

Commit 3fd4ac7

Browse files
committed
[2.0.44] Fixed promise retries on 404s (#7)
* Fixing promise retries on 404s * Version bump * README updates
1 parent e58830b commit 3fd4ac7

5 files changed

Lines changed: 19 additions & 17 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Check out [SUMMONER-V3](https://github.com/ChauTNguyen/kindred-api/wiki/SUMMONER
3030
* All standard endpoints covered but tournament endpoints.
3131
* Supports both **callbacks** and **promises**.
3232
* **Burst/Spread** rate limiter that is **enforced per region** and **follows retry headers**.
33-
* Retries on 429 and >= 500. (Doesn't retry on 404)
33+
* **Retries** on 429 and >= 500 **until all calls are successful**. (Doesn't retry on 404)
3434
* Built-in **parameter checks** so you can hopefully refer to documentation less! :)
3535
* Built-in **caching** (in-memory and Redis).
3636
* **Customized expiration timers**. You can set a timer for each endpoint type. Refer to [Caching](https://github.com/ChauTNguyen/kindred-api/wiki/Caching) for more info.
@@ -278,7 +278,7 @@ The difference between my site and other applications people seem to be working
278278

279279
## ~~Rate Limiter is not as optimized as it should be.~~ (FIXED 2.0.33)
280280

281-
## Promises retry on 404.
281+
## ~~Promises retry on 404.~~ (FIXED 2.0.43)
282282

283283
This is problematic because certain calls such as getCurrentGame, which will hit 404's often, will always retry up to 3 times.
284284

dist/kindred-api.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,16 +1011,21 @@
10111011
} else {
10121012
if (statusCode >= 500) {
10131013
if (self.debug) console.log('!!! resending promise request !!!');
1014+
setTimeout(function () {
1015+
(function () {
1016+
return resolve(tryRequest());
1017+
});
1018+
}, 1000);
10141019
setTimeout(function () {
10151020
return reject('retry');
10161021
}, 1000);
10171022
} else if (statusCode === 429) {
10181023
if (self.debug) console.log('!!! resending promise request !!!');
10191024
setTimeout(function () {
1020-
return reject('retry');
1025+
return resolve(tryRequest());
10211026
}, response.headers['retry-after'] * 1000 + 50);
10221027
} else if (error || statusCode >= 400) {
1023-
return reject('err:', error, statusCode);
1028+
return reject(statusMessage + ' : ' + chalk.yellow(reqUrl));
10241029
} else {
10251030
if (Number.isInteger(cacheParams.ttl) && cacheParams.ttl > 0) self.cache.set({ key: reqUrl, ttl: cacheParams.ttl }, body);
10261031
return resolve(JSON.parse(body));
@@ -1062,10 +1067,6 @@
10621067
});
10631068
};
10641069

1065-
if (!cb) return tryRequest().catch(tryRequest).catch(tryRequest).catch(tryRequest).then(function (data) {
1066-
return data;
1067-
});
1068-
10691070
return tryRequest();
10701071
}
10711072
}, {

dist/kindred-api.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kindred-api",
3-
"version": "2.0.43",
3+
"version": "2.0.44",
44
"description": "Node.js League of Legends v3 API wrapper with built-in rate-limiting (burst/spread, enforced per region), caching (in-memory, Redis), and parameter checking.",
55
"main": "index.js",
66
"jsnext:main": "src/index.js",

src/kindred-api.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,17 @@ class Kindred {
554554
} else {
555555
if (statusCode >= 500) {
556556
if (self.debug) console.log('!!! resending promise request !!!')
557+
setTimeout(() => {
558+
() => resolve(tryRequest())
559+
}, 1000)
557560
setTimeout(() => { return reject('retry') }, 1000)
558561
} else if (statusCode === 429) {
559562
if (self.debug) console.log('!!! resending promise request !!!')
560-
setTimeout(() => { return reject('retry') }, (response.headers['retry-after'] * 1000) + 50)
563+
setTimeout(() => {
564+
return resolve(tryRequest())
565+
}, (response.headers['retry-after'] * 1000) + 50)
561566
} else if (error || statusCode >= 400) {
562-
return reject('err:', error, statusCode)
567+
return reject(statusMessage + ' : ' + chalk.yellow(reqUrl))
563568
} else {
564569
if (Number.isInteger(cacheParams.ttl) && cacheParams.ttl > 0)
565570
self.cache.set({ key: reqUrl, ttl: cacheParams.ttl }, body)
@@ -605,10 +610,6 @@ class Kindred {
605610
})
606611
}
607612

608-
if (!cb) return tryRequest()
609-
.catch(tryRequest).catch(tryRequest).catch(tryRequest)
610-
.then(data => data)
611-
612613
return tryRequest()
613614
}
614615

0 commit comments

Comments
 (0)