Skip to content

Commit

Permalink
Merge pull request #30 from janvanmansum/DD-1626
Browse files Browse the repository at this point in the history
DD-1626 dd-sword2: error authenticating credentials
  • Loading branch information
janvanmansum authored Aug 30, 2024
2 parents 9d33b05 + 41ad00c commit 37d2dca
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,17 @@ public Optional<String> authenticateWithHeaders(MultivaluedMap<String, String> h
}

private Optional<String> doRequest(HttpUriRequest request) throws AuthenticationException, IOException {
final CloseableHttpResponse response = httpClient.execute(request);
final String reasonPhrase = response.getReasonPhrase();
int statusCode = response.getCode();
final Response.StatusType statusPhrase = Statuses.from(statusCode, reasonPhrase == null ? "" : reasonPhrase);
log.debug("Delegate returned status code {}", statusCode);
try (var response = httpClient.execute(request)) {
final String reasonPhrase = response.getReasonPhrase();
int statusCode = response.getCode();
final Response.StatusType statusPhrase = Statuses.from(statusCode, reasonPhrase == null ? "" : reasonPhrase);
log.debug("Delegate returned status code {}", statusCode);

switch (statusCode) {
case 200:
return getUsernameFromResponse(response);
case 401:
return Optional.empty();
default:
throw new AuthenticationException(String.format("Unexpected status code returned: %s (message: %s)", statusCode, statusPhrase));
return switch (statusCode) {
case 200 -> getUsernameFromResponse(response);
case 401 -> Optional.empty();
default -> throw new AuthenticationException(String.format("Unexpected status code returned: %s (message: %s)", statusCode, statusPhrase));
};
}
}

Expand Down

0 comments on commit 37d2dca

Please sign in to comment.