diff options
-rw-r--r-- | src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java | 14 |
1 files changed, 13 insertions, 1 deletions
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; @@ -41,6 +46,13 @@ public class ExceptionHandler { @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) { logger.error("Incorrect user input: " + exception.getMessage()); String messageKey = exception.getMessageResourceKey(); |