Check for "permission denied" without status code 403

This commit is contained in:
Stefan Kalscheuer 2016-06-19 20:11:56 +02:00
parent b845e4b7ce
commit 30ac23203d
2 changed files with 9 additions and 2 deletions

View File

@ -14,7 +14,7 @@ Java Vault Connector is a connector library for [Vault](https://www.vaultproject
* Write secrets
* List secrets
* Connector Factory with builder pattern
* Tested against Vault 0.5.2
* Tested against Vault 0.6.0
**Usage Example**

View File

@ -381,7 +381,14 @@ public class HTTPVaultConnector implements VaultConnector {
InvalidResponseException ex = new InvalidResponseException("Invalid response code")
.withStatusCode(response.getStatusLine().getStatusCode());
try {
throw ex.withResponse(IOUtils.toString(response.getEntity().getContent()));
/* Try to parse error response */
ErrorResponse er = jsonMapper.readValue(IOUtils.toString(response.getEntity().getContent()),
ErrorResponse.class);
/* Check for "permission denied" response */
if (er.getErrors().size() > 0 && er.getErrors().get(0).equals("permission denied"))
throw new PermissionDeniedException();
throw ex.withResponse(er.toString());
}
catch (IOException e) {
throw ex;