Skip to content

Commit

Permalink
Merge pull request #294 from cdapio/log_exceptions
Browse files Browse the repository at this point in the history
Log stack trace when NamingException is thrown
  • Loading branch information
rmstar authored Feb 16, 2024
2 parents 6d89359 + 570113e commit ef3fbd9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public DirContext getConnection() throws NamingException {
try {
return new InitialDirContext(properties);
} catch (NamingException e) {
LOG.warn("Failed connect to '{}' on attempt '{}'", config.getUrl(), i);
LOG.warn("Failed connect to '{}' on attempt '{}'", config.getUrl(), i, e);

// Throw error if maximum of attempts is reached
if (i == LDAPConstants.MAX_CONNECTION_RETRIES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,14 @@ public Set<String> searchGroups(String username) {
context.close();
}
} catch (NamingException e) {
Throwable cause = e.getCause();

// Getting informative error message
String exceptionMessage;
if (cause == null) {
exceptionMessage = e.getMessage();
} else {
exceptionMessage = cause.getMessage();
}

String errorMsg = String.format("Failed to find groups for user '%s': %s", username, exceptionMessage);
String errorMsg = String.format("Failed to find groups for user '%s'", username);

// Throw error if maximum of attempts is reached
if (i == LDAPConstants.MAX_SEARCH_RETRIES) {
throw new RuntimeException(errorMsg, e);
}

LOG.warn(errorMsg);
LOG.warn(errorMsg, e);
sleep(i * LDAPConstants.DEFAULT_RETRY_INTERVAL);
}
}
Expand Down

0 comments on commit ef3fbd9

Please sign in to comment.