From b814319994da9c5004e0b11ab387de75b83dad6c Mon Sep 17 00:00:00 2001 From: Jon Brisbin Date: Wed, 6 Mar 2013 11:27:05 -0600 Subject: [PATCH] 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. --- .../rest/webmvc/AbstractRepositoryRestController.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java index 53ed99ab0..e419c834c 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java @@ -133,7 +133,10 @@ public class AbstractRepositoryRestController implements ApplicationContextAware ConversionFailedException.class }) @ResponseBody - public ResponseEntity 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,