From 34b137fdc63217729fd08df3442b293ed480a8fb Mon Sep 17 00:00:00 2001 From: jbion Date: Tue, 20 Dec 2016 01:12:32 +0100 Subject: Add conversion exception handling for bad input JSON format --- .../org/luxons/sevenwonders/errors/ExceptionHandler.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java b/src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java index ca2e4062..9e26cbe3 100644 --- a/src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java +++ b/src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java @@ -7,6 +7,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; +import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.handler.annotation.MessageExceptionHandler; import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; import org.springframework.messaging.simp.annotation.SendToUser; @@ -20,7 +21,11 @@ public class ExceptionHandler { private static final String ERROR_CODE_VALIDATION = "VALIDATION_ERROR"; - private static final String ERROR_MSG_VALIDATION = "Input invalid"; + private static final String ERROR_CODE_CONVERSION = "MESSAGE_FORMAT_ERROR"; + + private static final String ERROR_MSG_VALIDATION = "Invalid input data"; + + private static final String ERROR_MSG_CONVERSION = "Invalid input format"; private final MessageSource messageSource; @@ -39,6 +44,13 @@ public class ExceptionHandler { return uiError; } + @MessageExceptionHandler + @SendToUser("/queue/errors") + private UIError handleConversionError(MessageConversionException exception) { + logger.error("Error interpreting the message", exception); + return new UIError(ERROR_CODE_CONVERSION, ERROR_MSG_CONVERSION, ErrorType.VALIDATION); + } + @MessageExceptionHandler @SendToUser("/queue/errors") private UIError handleGenericUserError(UserInputException exception) { -- cgit