@@ -37,8 +37,6 @@ const EntityStorage = require('./EntityStorage');
37
37
const ACCESS_TOKEN_RENEW_BEFORE_EXPIRY_MS = 3 * 60 * 1000 ; // 3 min
38
38
const LIST_PAGE_SIZE = 100 ;
39
39
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 ;
42
40
43
41
// Helper class for imp-central-api library requests.
44
42
class ImpCentralApiHelper {
@@ -495,24 +493,24 @@ class ImpCentralApiHelper {
495
493
return result ;
496
494
}
497
495
498
- _processImpCentralApiReq ( refreshAccessTokenOnAuthError , refreshTokenAttempts , entityType , id , impCentralApiMethod , ...args ) {
496
+ _processImpCentralApiRequest ( refreshAccessTokenOnAuthError , entityType , id , impCentralApiMethod , ...args ) {
499
497
UserInteractor . spinnerStart ( ) ;
500
498
return impCentralApiMethod ( ...args ) .
501
499
then ( result => this . _resolveImpCentralApiResponse ( result ) ) .
502
500
catch ( error => {
503
501
if ( this . _isAuthenticationError ( error ) ) {
504
- if ( refreshAccessTokenOnAuthError && refreshTokenAttempts < REFRESH_TOKEN_ATTEMPTS_LIMIT ) {
502
+ if ( refreshAccessTokenOnAuthError ) {
505
503
// try to refresh access token in case of authentication error and then restart the original request
506
504
return this . _refreshAccessToken ( ) .
507
- then ( ( ) => this . _processImpCentralApiReq (
508
- refreshAccessTokenOnAuthError , ++ refreshTokenAttempts , entityType , id , impCentralApiMethod , ...args ) ) ;
505
+ then ( ( ) => this . _processImpCentralApiRequest (
506
+ false , entityType , id , impCentralApiMethod , ...args ) ) ;
509
507
}
510
508
}
511
509
else if ( this . _isRateLimitError ( error ) ) {
512
510
return new Promise ( ( resolve , reject ) => {
513
511
setTimeout ( ( ) => resolve ( ) , 1000 )
514
- } ) . then ( ( ) => this . _processImpCentralApiReq (
515
- refreshAccessTokenOnAuthError , refreshTokenAttempts , entityType , id , impCentralApiMethod , ...args ) ) ;
512
+ } ) . then ( ( ) => this . _processImpCentralApiRequest (
513
+ refreshAccessTokenOnAuthError , entityType , id , impCentralApiMethod , ...args ) ) ;
516
514
}
517
515
else if ( this . _isEntityNotFoundError ( error ) && entityType && id ) {
518
516
throw new Errors . EntityNotFoundError ( entityType , id ) ;
@@ -521,10 +519,6 @@ class ImpCentralApiHelper {
521
519
} ) ;
522
520
}
523
521
524
- _processImpCentralApiRequest ( refreshAccessTokenOnAuthError , entityType , id , impCentralApiMethod , ...args ) {
525
- return this . _processImpCentralApiReq ( refreshAccessTokenOnAuthError , 0 , entityType , id , impCentralApiMethod , ...args ) ;
526
- }
527
-
528
522
_isEntityNotFoundError ( error ) {
529
523
return error instanceof ImpCentralApi . Errors . ImpCentralApiError &&
530
524
error . _statusCode === 404 ;
0 commit comments