Skip to content

Commit e1eae5a

Browse files
authored
Merge pull request #12 from prodatakey/bugfix/PDKIO-1761-handle-429-error-dufing-token-refresh
PDKIO-1761: refactoring to isolate 429 error
2 parents a5eea13 + 5d352a5 commit e1eae5a

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/authenticators/client.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,23 @@ async () => {
5252
if(!outstanding) {
5353
debug(`Getting token with client credentials`);
5454

55-
outstanding = client.grant({ grant_type: 'client_credentials' })
56-
55+
let grantWrapFunc = async () => {
56+
let result = client.grant({ grant_type: 'client_credentials' })
57+
try {
58+
return await result;
59+
} catch(err) {
60+
if (err && err.statusCode === 429) {
61+
await _sleep(1000);
62+
return await grantWrapFunc();
63+
}
64+
throw err;
65+
}
66+
}
67+
outstanding = grantWrapFunc();
5768
try {
5869
token_set = await outstanding
70+
} finally {
5971
outstanding = undefined
60-
} catch(err) {
61-
outstanding = undefined
62-
if (err && err.statusCode === 429) {
63-
await _sleep(1000);
64-
await oauthtoken_set.refresh();
65-
}
6672
}
6773

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

0 commit comments

Comments
 (0)