Skip to content

Commit

Permalink
GEODE-6174: Don't catch IllegalArgumentException from the validator (#…
Browse files Browse the repository at this point in the history
…3226)

Added a handler for IllegalArgumentException in the ManagementControllerAdvice to return
HttpStatus 400.
  • Loading branch information
Kenneth Howe authored and jdeppe-pivotal committed Feb 25, 2019
1 parent affee69 commit c10fe07
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Expand Up @@ -88,11 +88,7 @@ public ClusterManagementResult create(CacheElement config, String group) {

ConfigurationValidator validator = validators.get(config.getClass());
if (validator != null) {
try {
validator.validate(config);
} catch (IllegalArgumentException e) {
return new ClusterManagementResult(false, e.getMessage());
}
validator.validate(config);
}


Expand Down
Expand Up @@ -78,10 +78,9 @@ public void elementAlreadyExist() throws Exception {

@Test
public void validationFailed() throws Exception {
result = service.create(regionConfig, "cluster");
assertThat(result.isSuccessful()).isFalse();
assertThat(result.getPersistenceStatus().getMessage())
.contains("Name of the region has to be specified");
assertThatThrownBy(() -> service.create(regionConfig, "cluster"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Name of the region has to be specified");
}

@Test
Expand Down
Expand Up @@ -67,6 +67,12 @@ public ResponseEntity<ClusterManagementResult> badRequest(final MalformedObjectN
HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<ClusterManagementResult> badRequest(final IllegalArgumentException e) {
return new ResponseEntity<>(new ClusterManagementResult(false, e.getMessage()),
HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(InstanceNotFoundException.class)
public ResponseEntity<ClusterManagementResult> notFound(final InstanceNotFoundException e) {
return new ResponseEntity<>(new ClusterManagementResult(false, e.getMessage()),
Expand Down

0 comments on commit c10fe07

Please sign in to comment.