From d811c8f0115d2f697d82b556d5201400f0d14de3 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Tue, 11 Sep 2012 14:02:06 -0300 Subject: [PATCH] Handle validations exceptions. --- .../src/main/java/com/wisemapping/rest/BaseController.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java b/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java index 404455e3..884ae2fe 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/BaseController.java @@ -67,10 +67,15 @@ public class BaseController { return ex.getMessage(); } + @ExceptionHandler(ValidationException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public RestErrors handleValidationErrors(@NotNull ValidationException ex) { + return new RestErrors(ex.getErrors(), messageSource); + } @ExceptionHandler(JsonHttpMessageNotReadableException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) - public String handleValidationErrors(@NotNull JsonHttpMessageNotReadableException ex) { + public String handleJSONErrors(@NotNull JsonHttpMessageNotReadableException ex) { return "Request could not be saved. Message is not valid"; }