Skip to content

Commit

Permalink
Merge pull request cdapio#15380 from cdapio/bugfixes/cdap-20861
Browse files Browse the repository at this point in the history
[CDAP-20861] Improve OAuth logging and error handling
  • Loading branch information
masoud-io authored Oct 26, 2023
2 parents 10c3cda + 5565ac1 commit a784b2d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,16 @@ public void getOAuthCredential(HttpServiceRequest request, HttpServiceResponder
} catch (IOException e) {
throw new OAuthServiceException(HttpURLConnection.HTTP_INTERNAL_ERROR, "Failed to fetch refresh token", e);
}

if (response.getResponseCode() != 200) {
throw new OAuthServiceException(
HttpURLConnection.HTTP_INTERNAL_ERROR,
"Request for refresh token did not return 200: " + response.getResponseCode());
"Request for refresh token did not return 200. Response code: "
+ response.getResponseCode()
+ " , response message: "
+ response.getResponseMessage()
+ " , respone body: "
+ response.getResponseBodyAsString());
}

RefreshTokenResponse refreshTokenResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ public String evaluate(String macroFunction, String... args) throws InvalidMacro
double maxMultiplier =
RETRY_DELAY_MULTIPLIER + RETRY_DELAY_MULTIPLIER * RETRY_RANDOMIZE_FACTOR;
Stopwatch stopWatch = new Stopwatch().start();
int retryCount = 0;
RetryableException retryableException = null;
try {
while (stopWatch.elapsedTime(TimeUnit.MILLISECONDS) < TIMEOUT_MILLIS) {
try {
retryCount++;
return evaluateMacro(macroFunction, args);
} catch (RetryableException e) {
retryableException = e;
TimeUnit.MILLISECONDS.sleep(delay);
delay =
(long) (delay * (minMultiplier + Math.random() * (maxMultiplier - minMultiplier
Expand All @@ -86,13 +90,38 @@ public String evaluate(String macroFunction, String... args) throws InvalidMacro
}
}
} catch (InterruptedException e) {
throw new RuntimeException("Thread interrupted while trying evaluate "
+ "the value for '" + functionName + "' with"
+ " args " + Arrays.asList(args), e);
throw new RuntimeException(
"Thread interrupted while trying evaluate "
+ "the value for '"
+ functionName
+ "' with"
+ " args "
+ Arrays.asList(args),
e);
}

if (retryableException == null) {
throw new IllegalStateException(
"Exception after "
+ retryCount
+ " times trying to evaluate the "
+ "value for '"
+ functionName
+ "' with "
+ "args "
+ Arrays.asList(args));
}
throw new IllegalStateException("Timed out when trying to evaluate the "
+ "value for '" + functionName + "' with "
+ "args " + Arrays.asList(args));

throw new IllegalStateException(
"Exception after "
+ retryCount
+ " times trying to evaluate the "
+ "value for '"
+ functionName
+ "' with "
+ "args "
+ Arrays.asList(args),
retryableException);
}

@Override
Expand Down

0 comments on commit a784b2d

Please sign in to comment.