Skip to content

Commit

Permalink
FFM-6964 - Add broader exception handling in case authentication fails (
Browse files Browse the repository at this point in the history
#137)

Also only wait for 5 seconds instead of forever, allowing the failure check to proppogate
  • Loading branch information
checketts authored Feb 21, 2023
1 parent b2bdbe0 commit 588e42e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/main/java/io/harness/cf/client/api/AuthCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

interface AuthCallback {
void onAuthSuccess();

void onFailure(final String message);
}
14 changes: 10 additions & 4 deletions src/main/java/io/harness/cf/client/api/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ protected void runOneIteration() {
stopAsync();
log.info("Stopping Auth service");
} catch (ConnectorException e) {
log.error(
"Exception while authenticating, retry in {} seconds, error: {}",
pollIntervalInSec,
e.getMessage());
if (e.shouldRetry()) {
log.error(
"Exception while authenticating, retry in {} seconds, error: {}",
pollIntervalInSec,
e.getMessage());
} else {
stopAsync();
log.error("Exception while authenticating", e);
callback.onFailure(e.getMessage());
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/harness/cf/client/api/InnerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public synchronized void waitForInitialization()
throws InterruptedException, FeatureFlagInitializeException {
while (!initialized) {
log.info("Wait for initialization to finish");
wait();
wait(5000);

if (failure) {
log.error("Failure while initializing SDK!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,33 @@
public class ConnectorException extends Exception {

private final int httpCode;
private final boolean shouldRetry;

private final String httpReason;

public ConnectorException(String message) {
super(message);
this.httpCode = 0;
this.httpReason = "";
this.shouldRetry = true;
}

public ConnectorException(String message, int httpCode, String httpMsg) {
super(message);
this.httpCode = httpCode;
this.httpReason = httpMsg;
this.shouldRetry = true;
}

public ConnectorException(String message, boolean shouldRetry, Exception e) {
super(message, e);
this.shouldRetry = shouldRetry;
this.httpCode = 0;
this.httpReason = "";
}

public boolean shouldRetry() {
return shouldRetry;
}

@Override
Expand Down

0 comments on commit 588e42e

Please sign in to comment.