Skip to content

Commit

Permalink
Merge pull request #12 from prodatakey/bugfix/PDKIO-1761-handle-429-e…
Browse files Browse the repository at this point in the history
…rror-dufing-token-refresh

PDKIO-1761: refactoring to isolate 429 error
  • Loading branch information
dima11051994 authored Jan 25, 2021
2 parents a5eea13 + 5d352a5 commit e1eae5a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/authenticators/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ async () => {
if(!outstanding) {
debug(`Getting token with client credentials`);

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

let grantWrapFunc = async () => {
let result = client.grant({ grant_type: 'client_credentials' })
try {
return await result;
} catch(err) {
if (err && err.statusCode === 429) {
await _sleep(1000);
return await grantWrapFunc();
}
throw err;
}
}
outstanding = grantWrapFunc();
try {
token_set = await outstanding
} finally {
outstanding = undefined
} catch(err) {
outstanding = undefined
if (err && err.statusCode === 429) {
await _sleep(1000);
await oauthtoken_set.refresh();
}
}

debug(`Got fresh token: ${JSON.stringify(token_set)}`);
Expand Down

0 comments on commit e1eae5a

Please sign in to comment.