@@ -91,8 +91,8 @@ private LogicalResponse read(final String path, Boolean shouldRetry, final logic
91
91
.sslContext (config .getSslConfig ().getSslContext ())
92
92
.get ();
93
93
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 ) ) {
96
96
throw new VaultException ("Vault responded with HTTP status code: " + restResponse .getStatus ()
97
97
+ "\n Response body: " + new String (restResponse .getBody (), StandardCharsets .UTF_8 ),
98
98
restResponse .getStatus ());
@@ -160,8 +160,8 @@ public LogicalResponse read(final String path, Boolean shouldRetry, final Intege
160
160
.sslContext (config .getSslConfig ().getSslContext ())
161
161
.get ();
162
162
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 ) ) {
165
165
throw new VaultException ("Vault responded with HTTP status code: " + restResponse .getStatus ()
166
166
+ "\n Response body: " + new String (restResponse .getBody (), StandardCharsets .UTF_8 ),
167
167
restResponse .getStatus ());
@@ -261,7 +261,7 @@ private LogicalResponse write(final String path, final Map<String, Object> nameV
261
261
262
262
// HTTP Status should be either 200 (with content - e.g. PKI write) or 204 (no content)
263
263
final int restStatus = restResponse .getStatus ();
264
- if (restStatus == 200 || restStatus == 204 ) {
264
+ if (restStatus == 200 || restStatus == 204 || ( restResponse . getStatus () >= 400 && restResponse . getStatus () < 500 ) ) {
265
265
return new LogicalResponse (restResponse , retryCount , operation );
266
266
} else {
267
267
throw new VaultException ("Expecting HTTP status 204 or 200, but instead receiving " + restStatus
0 commit comments