Skip to content

Commit d3830da

Browse files
committed
support reconnections/retries for login-key commands
1 parent 0279d78 commit d3830da

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

Diff for: lib/util/ImpCentralApiHelper.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ const EntityStorage = require('./EntityStorage');
3737
const ACCESS_TOKEN_RENEW_BEFORE_EXPIRY_MS = 3 * 60 * 1000; // 3 min
3838
const LIST_PAGE_SIZE = 100;
3939
const CONCURRENT_REQUESTS_LIMIT = 5;
40-
// maximum number of attemts to refresh access token and restart an original request in case of authentication error
41-
const REFRESH_TOKEN_ATTEMPTS_LIMIT = 5;
4240

4341
// Helper class for imp-central-api library requests.
4442
class ImpCentralApiHelper {
@@ -495,24 +493,24 @@ class ImpCentralApiHelper {
495493
return result;
496494
}
497495

498-
_processImpCentralApiReq(refreshAccessTokenOnAuthError, refreshTokenAttempts, entityType, id, impCentralApiMethod, ...args) {
496+
_processImpCentralApiRequest(refreshAccessTokenOnAuthError, entityType, id, impCentralApiMethod, ...args) {
499497
UserInteractor.spinnerStart();
500498
return impCentralApiMethod(...args).
501499
then(result => this._resolveImpCentralApiResponse(result)).
502500
catch(error => {
503501
if (this._isAuthenticationError(error)) {
504-
if (refreshAccessTokenOnAuthError && refreshTokenAttempts < REFRESH_TOKEN_ATTEMPTS_LIMIT) {
502+
if (refreshAccessTokenOnAuthError) {
505503
// try to refresh access token in case of authentication error and then restart the original request
506504
return this._refreshAccessToken().
507-
then(() => this._processImpCentralApiReq(
508-
refreshAccessTokenOnAuthError, ++refreshTokenAttempts, entityType, id, impCentralApiMethod, ...args));
505+
then(() => this._processImpCentralApiRequest(
506+
false, entityType, id, impCentralApiMethod, ...args));
509507
}
510508
}
511509
else if (this._isRateLimitError(error)) {
512510
return new Promise((resolve, reject) => {
513511
setTimeout(() => resolve(), 1000)
514-
}).then(() => this._processImpCentralApiReq(
515-
refreshAccessTokenOnAuthError, refreshTokenAttempts, entityType, id, impCentralApiMethod, ...args));
512+
}).then(() => this._processImpCentralApiRequest(
513+
refreshAccessTokenOnAuthError, entityType, id, impCentralApiMethod, ...args));
516514
}
517515
else if (this._isEntityNotFoundError(error) && entityType && id) {
518516
throw new Errors.EntityNotFoundError(entityType, id);
@@ -521,10 +519,6 @@ class ImpCentralApiHelper {
521519
});
522520
}
523521

524-
_processImpCentralApiRequest(refreshAccessTokenOnAuthError, entityType, id, impCentralApiMethod, ...args) {
525-
return this._processImpCentralApiReq(refreshAccessTokenOnAuthError, 0, entityType, id, impCentralApiMethod, ...args);
526-
}
527-
528522
_isEntityNotFoundError(error) {
529523
return error instanceof ImpCentralApi.Errors.ImpCentralApiError &&
530524
error._statusCode === 404;

0 commit comments

Comments
 (0)