Skip to content

Commit 588e42e

Browse files
authored
FFM-6964 - Add broader exception handling in case authentication fails (#137)
Also only wait for 5 seconds instead of forever, allowing the failure check to proppogate
1 parent b2bdbe0 commit 588e42e

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

src/main/java/io/harness/cf/client/api/AuthCallback.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
interface AuthCallback {
44
void onAuthSuccess();
5+
6+
void onFailure(final String message);
57
}

src/main/java/io/harness/cf/client/api/AuthService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ protected void runOneIteration() {
3333
stopAsync();
3434
log.info("Stopping Auth service");
3535
} catch (ConnectorException e) {
36-
log.error(
37-
"Exception while authenticating, retry in {} seconds, error: {}",
38-
pollIntervalInSec,
39-
e.getMessage());
36+
if (e.shouldRetry()) {
37+
log.error(
38+
"Exception while authenticating, retry in {} seconds, error: {}",
39+
pollIntervalInSec,
40+
e.getMessage());
41+
} else {
42+
stopAsync();
43+
log.error("Exception while authenticating", e);
44+
callback.onFailure(e.getMessage());
45+
}
4046
}
4147
}
4248

src/main/java/io/harness/cf/client/api/InnerClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public synchronized void waitForInitialization()
335335
throws InterruptedException, FeatureFlagInitializeException {
336336
while (!initialized) {
337337
log.info("Wait for initialization to finish");
338-
wait();
338+
wait(5000);
339339

340340
if (failure) {
341341
log.error("Failure while initializing SDK!");

src/main/java/io/harness/cf/client/connector/ConnectorException.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,33 @@
33
public class ConnectorException extends Exception {
44

55
private final int httpCode;
6+
private final boolean shouldRetry;
7+
68
private final String httpReason;
79

810
public ConnectorException(String message) {
911
super(message);
1012
this.httpCode = 0;
1113
this.httpReason = "";
14+
this.shouldRetry = true;
1215
}
1316

1417
public ConnectorException(String message, int httpCode, String httpMsg) {
1518
super(message);
1619
this.httpCode = httpCode;
1720
this.httpReason = httpMsg;
21+
this.shouldRetry = true;
22+
}
23+
24+
public ConnectorException(String message, boolean shouldRetry, Exception e) {
25+
super(message, e);
26+
this.shouldRetry = shouldRetry;
27+
this.httpCode = 0;
28+
this.httpReason = "";
29+
}
30+
31+
public boolean shouldRetry() {
32+
return shouldRetry;
1833
}
1934

2035
@Override

0 commit comments

Comments
 (0)