Capture the case where a ResourceNotFoundException was in the cause of an IllegalArgumentException. This situation should result in a 404 not a 500 with an error message.

This commit is contained in:
Jon Brisbin
2013-03-06 11:27:05 -06:00
parent 1a7adc6461
commit b814319994

View File

@@ -133,7 +133,10 @@ public class AbstractRepositoryRestController implements ApplicationContextAware
ConversionFailedException.class
})
@ResponseBody
public ResponseEntity<ExceptionMessage> handleMiscFailures(Throwable t) {
public ResponseEntity handleMiscFailures(Throwable t) {
if(null != t.getCause() && t.getCause() instanceof ResourceNotFoundException) {
return notFound();
}
return badRequest(t);
}
@@ -143,6 +146,10 @@ public class AbstractRepositoryRestController implements ApplicationContextAware
@ResponseBody
public ResponseEntity maybeHandleValidationException(Locale locale,
RuntimeException ex) {
if(ResourceNotFoundException.class.isAssignableFrom(ex.getClass())) {
return handleNotFound();
}
if(null != handler) {
return handler.handleValidationException(ex,
applicationContext,