Throw more speaking Exception when parsing body failed
Removed the fall-through behavior in code 200 exception.
This commit is contained in:
parent
7ac550230f
commit
8ae4dccdd6
@ -60,6 +60,8 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
private static final String PATH_AUTH_APPROLE = "auth/approle/";
|
private static final String PATH_AUTH_APPROLE = "auth/approle/";
|
||||||
private static final String PATH_REVOKE = "sys/revoke/";
|
private static final String PATH_REVOKE = "sys/revoke/";
|
||||||
|
|
||||||
|
private static final String HEADER_VAULT_TOKEN = "X-Vault-Token";
|
||||||
|
|
||||||
private final ObjectMapper jsonMapper;
|
private final ObjectMapper jsonMapper;
|
||||||
|
|
||||||
private final String baseURL; /* Base URL of Vault */
|
private final String baseURL; /* Base URL of Vault */
|
||||||
@ -709,7 +711,7 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
post.setEntity(input);
|
post.setEntity(input);
|
||||||
/* Set X-Vault-Token header */
|
/* Set X-Vault-Token header */
|
||||||
if (token != null)
|
if (token != null)
|
||||||
post.addHeader("X-Vault-Token", token);
|
post.addHeader(HEADER_VAULT_TOKEN, token);
|
||||||
|
|
||||||
return request(post, retries);
|
return request(post, retries);
|
||||||
}
|
}
|
||||||
@ -736,7 +738,7 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
put.setEntity(entity);
|
put.setEntity(entity);
|
||||||
/* Set X-Vault-Token header */
|
/* Set X-Vault-Token header */
|
||||||
if (token != null)
|
if (token != null)
|
||||||
put.addHeader("X-Vault-Token", token);
|
put.addHeader(HEADER_VAULT_TOKEN, token);
|
||||||
|
|
||||||
return request(put, retries);
|
return request(put, retries);
|
||||||
}
|
}
|
||||||
@ -753,7 +755,7 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
HttpDelete delete = new HttpDelete(baseURL + path);
|
HttpDelete delete = new HttpDelete(baseURL + path);
|
||||||
/* Set X-Vault-Token header */
|
/* Set X-Vault-Token header */
|
||||||
if (token != null)
|
if (token != null)
|
||||||
delete.addHeader("X-Vault-Token", token);
|
delete.addHeader(HEADER_VAULT_TOKEN, token);
|
||||||
|
|
||||||
return request(delete, retries);
|
return request(delete, retries);
|
||||||
}
|
}
|
||||||
@ -778,7 +780,7 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
|
|
||||||
/* Set X-Vault-Token header */
|
/* Set X-Vault-Token header */
|
||||||
if (token != null)
|
if (token != null)
|
||||||
get.addHeader("X-Vault-Token", token);
|
get.addHeader(HEADER_VAULT_TOKEN, token);
|
||||||
|
|
||||||
return request(get, retries);
|
return request(get, retries);
|
||||||
}
|
}
|
||||||
@ -812,6 +814,7 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
new InputStreamReader(response.getEntity().getContent()))) {
|
new InputStreamReader(response.getEntity().getContent()))) {
|
||||||
return br.lines().collect(Collectors.joining("\n"));
|
return br.lines().collect(Collectors.joining("\n"));
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
|
throw new InvalidResponseException("Could not parse response body").withStatusCode(200);
|
||||||
}
|
}
|
||||||
case 204:
|
case 204:
|
||||||
return "";
|
return "";
|
||||||
@ -832,10 +835,11 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
String responseString = br.lines().collect(Collectors.joining("\n"));
|
String responseString = br.lines().collect(Collectors.joining("\n"));
|
||||||
ErrorResponse er = jsonMapper.readValue(responseString, ErrorResponse.class);
|
ErrorResponse er = jsonMapper.readValue(responseString, ErrorResponse.class);
|
||||||
/* Check for "permission denied" response */
|
/* Check for "permission denied" response */
|
||||||
if (er.getErrors().size() > 0 && er.getErrors().get(0).equals("permission denied"))
|
if (!er.getErrors().isEmpty() && er.getErrors().get(0).equals("permission denied"))
|
||||||
throw new PermissionDeniedException();
|
throw new PermissionDeniedException();
|
||||||
throw ex.withResponse(er.toString());
|
throw ex.withResponse(er.toString());
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
|
// Exception ignored.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw ex;
|
throw ex;
|
||||||
@ -848,6 +852,7 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
try {
|
try {
|
||||||
EntityUtils.consume(response.getEntity());
|
EntityUtils.consume(response.getEntity());
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
|
// Exception ignored.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user