Skip to content

Commit

Permalink
PDKIO-1761: refactoring to isolate 429 error
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kostyuchenko committed Jan 25, 2021
1 parent f99d6fc commit cf205e5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/authenticators/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,22 @@ 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 grantWrapFunc
}
}
}
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 cf205e5

Please sign in to comment.