Skip to content

Commit a5eea13

Browse files
authored
Merge pull request #11 from prodatakey/bugfix/PDKIO-1761-handle-429-error-dufing-token-refresh
PDKIO-1761: timeout is increased and handle 429 error
2 parents 74d9f57 + f99d6fc commit a5eea13

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
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": "@pdk/client",
3-
"version": "0.7.1",
3+
"version": "0.7.2",
44
"description": "ProdataKey pdk.io API Client Library for Javascript",
55
"scripts": {
66
"test": "mocha -r src/test/setup.js -r esm \"src/**/*.spec.js\"",

src/authenticators/client.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const clientauth = ({
2222
}) =>
2323
async () => {
2424
// merge provided default http options with PDK defaults and set it to the Issuer object
25-
Issuer.defaultHttpOptions = {timeout: 10000, retries: 1, ...default_http_options}
25+
Issuer.defaultHttpOptions = {timeout: 60000, retries: 1, ...default_http_options}
2626

2727
debug(`Authenticating as client_id: ${client_id}`);
2828

@@ -54,8 +54,16 @@ async () => {
5454

5555
outstanding = client.grant({ grant_type: 'client_credentials' })
5656

57-
token_set = await outstanding
58-
outstanding = undefined
57+
try {
58+
token_set = await outstanding
59+
outstanding = undefined
60+
} catch(err) {
61+
outstanding = undefined
62+
if (err && err.statusCode === 429) {
63+
await _sleep(1000);
64+
await oauthtoken_set.refresh();
65+
}
66+
}
5967

6068
debug(`Got fresh token: ${JSON.stringify(token_set)}`);
6169
} else {
@@ -74,3 +82,7 @@ async () => {
7482
await oauthtoken_set.refresh();
7583
return oauthtoken_set;
7684
}
85+
86+
function _sleep(ms) {
87+
return new Promise(resolve => setTimeout(resolve, ms));
88+
}

0 commit comments

Comments
 (0)