summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-20 01:12:32 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-20 01:12:32 +0100
commit34b137fdc63217729fd08df3442b293ed480a8fb (patch)
treeab156231154dfc488037d4511ac715f296d45255 /src
parentAdd response with list of games at subscription to /topic/games (diff)
downloadseven-wonders-34b137fdc63217729fd08df3442b293ed480a8fb.tar.gz
seven-wonders-34b137fdc63217729fd08df3442b293ed480a8fb.tar.bz2
seven-wonders-34b137fdc63217729fd08df3442b293ed480a8fb.zip
Add conversion exception handling for bad input JSON format
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java14
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();
bgstack15