Skip to content

Commit

Permalink
PDKIO-1761: timeout is increased and handle 429 error
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kostyuchenko committed Jan 22, 2021
1 parent 74d9f57 commit 76f8d26
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pdk/client",
"version": "0.7.1",
"version": "0.7.2",
"description": "ProdataKey pdk.io API Client Library for Javascript",
"scripts": {
"test": "mocha -r src/test/setup.js -r esm \"src/**/*.spec.js\"",
Expand Down
18 changes: 15 additions & 3 deletions src/authenticators/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const clientauth = ({
}) =>
async () => {
// merge provided default http options with PDK defaults and set it to the Issuer object
Issuer.defaultHttpOptions = {timeout: 10000, retries: 1, ...default_http_options}
Issuer.defaultHttpOptions = {timeout: 60000, retries: 1, ...default_http_options}

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

Expand Down Expand Up @@ -54,8 +54,16 @@ async () => {

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

token_set = await outstanding
outstanding = undefined
try {
token_set = await outstanding
outstanding = undefined
} catch(err) {
outstanding = undefined
if (err && err.statusCode === 429) {
_sleep(4000);
await oauthtoken_set.refresh();
}
}

debug(`Got fresh token: ${JSON.stringify(token_set)}`);
} else {
Expand All @@ -74,3 +82,7 @@ async () => {
await oauthtoken_set.refresh();
return oauthtoken_set;
}

function _sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

0 comments on commit 76f8d26

Please sign in to comment.