From cf205e59a6f29e447fcda3fb49dedcc76d7b8f41 Mon Sep 17 00:00:00 2001 From: Andrey Kostyuchenko Date: Mon, 25 Jan 2021 10:03:01 +0300 Subject: [PATCH 1/2] PDKIO-1761: refactoring to isolate 429 error --- src/authenticators/client.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/authenticators/client.js b/src/authenticators/client.js index 11d667c..02c6e0f 100644 --- a/src/authenticators/client.js +++ b/src/authenticators/client.js @@ -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)}`); From 5d352a595a9cbc22fbb597f2d03441a4a50ee718 Mon Sep 17 00:00:00 2001 From: Andrey Kostyuchenko Date: Mon, 25 Jan 2021 14:21:51 +0300 Subject: [PATCH 2/2] PDKIO-1761: throw not 429 error --- src/authenticators/client.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/authenticators/client.js b/src/authenticators/client.js index 02c6e0f..570bfd3 100644 --- a/src/authenticators/client.js +++ b/src/authenticators/client.js @@ -59,8 +59,9 @@ async () => { } catch(err) { if (err && err.statusCode === 429) { await _sleep(1000); - return grantWrapFunc + return await grantWrapFunc(); } + throw err; } } outstanding = grantWrapFunc();