@@ -91,8 +91,8 @@ private LogicalResponse read(final String path, Boolean shouldRetry, final logic
9191 .sslContext (config .getSslConfig ().getSslContext ())
9292 .get ();
9393
94- // Validate response
95- if (restResponse .getStatus () != 200 ) {
94+ // Validate response - don't treat 4xx class errors as exceptions, we want to return an error as the response
95+ if (restResponse .getStatus () != 200 && !( restResponse . getStatus () >= 400 && restResponse . getStatus () < 500 ) ) {
9696 throw new VaultException ("Vault responded with HTTP status code: " + restResponse .getStatus ()
9797 + "\n Response body: " + new String (restResponse .getBody (), StandardCharsets .UTF_8 ),
9898 restResponse .getStatus ());
@@ -160,8 +160,8 @@ public LogicalResponse read(final String path, Boolean shouldRetry, final Intege
160160 .sslContext (config .getSslConfig ().getSslContext ())
161161 .get ();
162162
163- // Validate response
164- if (restResponse .getStatus () != 200 ) {
163+ // Validate response - don't treat 4xx class errors as exceptions, we want to return an error as the response
164+ if (restResponse .getStatus () != 200 && !( restResponse . getStatus () >= 400 && restResponse . getStatus () < 500 ) ) {
165165 throw new VaultException ("Vault responded with HTTP status code: " + restResponse .getStatus ()
166166 + "\n Response body: " + new String (restResponse .getBody (), StandardCharsets .UTF_8 ),
167167 restResponse .getStatus ());
@@ -261,7 +261,7 @@ private LogicalResponse write(final String path, final Map<String, Object> nameV
261261
262262 // HTTP Status should be either 200 (with content - e.g. PKI write) or 204 (no content)
263263 final int restStatus = restResponse .getStatus ();
264- if (restStatus == 200 || restStatus == 204 ) {
264+ if (restStatus == 200 || restStatus == 204 || ( restResponse . getStatus () >= 400 && restResponse . getStatus () < 500 ) ) {
265265 return new LogicalResponse (restResponse , retryCount , operation );
266266 } else {
267267 throw new VaultException ("Expecting HTTP status 204 or 200, but instead receiving " + restStatus
0 commit comments