Skip to content

Commit

Permalink
handled null and exception scenario for authtoken
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikmashru committed Apr 25, 2024
1 parent b6c8a14 commit 95687c2
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ public void run() {
return;
}
final String authToken = authHandler.onAuthTokenRequested();
pendingAuth = false;
retryCount++;
handleAuthTokenSuccess(authToken, successCallback);
} catch (final Exception e) {
retryCount++;
handleAuthTokenFailure(e);
}
}
Expand Down Expand Up @@ -127,7 +129,6 @@ private void handleAuthTokenSuccess(String authToken, IterableHelper.SuccessHand
return;
}
IterableApi.getInstance().setAuthToken(authToken);
pendingAuth = false;
reSyncAuth();
authHandler.onTokenRegistrationSuccessful(authToken);
}
Expand All @@ -136,7 +137,7 @@ private void handleAuthTokenFailure(Throwable throwable) {
IterableLogger.e(TAG, "Error while requesting Auth Token", throwable);
authHandler.onTokenRegistrationFailed(throwable);
pendingAuth = false;
reSyncAuth();
scheduleAuthTokenRefresh(getNextRetryInterval(), false, null);
}

public void queueExpirationRefresh(String encodedJWT) {
Expand Down Expand Up @@ -164,7 +165,7 @@ void resetFailedAuth() {
void reSyncAuth() {
if (requiresAuthRefresh) {
requiresAuthRefresh = false;
requestNewAuthToken(false);
scheduleAuthTokenRefresh(getNextRetryInterval(), false, null);
}
}

Expand All @@ -178,7 +179,7 @@ long getNextRetryInterval() {
}

void scheduleAuthTokenRefresh(long timeDuration, boolean isScheduledRefresh, final IterableHelper.SuccessHandler successCallback) {
if (pauseAuthRetry && !isScheduledRefresh && isTimerScheduled) {
if ((pauseAuthRetry && !isScheduledRefresh) || isTimerScheduled) {
// we only stop schedule token refresh if it is called from retry (in case of failure). The normal auth token refresh schedule would work
return;
}
Expand Down

0 comments on commit 95687c2

Please sign in to comment.