/** * Create a {@link VaultLoginException} given {@code authMethod} and a * {@link Throwable cause}. * * @param authMethod must not be {@literal null}. * @param cause must not be {@literal null}. * @return the {@link VaultLoginException}. */ public static VaultLoginException create(String authMethod, Throwable cause) { if (cause instanceof RestClientResponseException) { String response = ((RestClientResponseException) cause) .getResponseBodyAsString(); return new VaultLoginException(String.format("Cannot login using %s: %s", authMethod, VaultResponses.getError(response)), cause); } return new VaultLoginException(String.format("Cannot login using %s", cause)); } }