diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2017-01-16 23:13:04 +0100 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2017-01-16 23:13:04 +0100 |
commit | deddd5ef5e8593009cd0e7dce699a459d497a727 (patch) | |
tree | 4d74ef833ff5dec53982dce0b104d23b5adf6fb7 /src/main/java/org | |
parent | Add Travis config for automatic deployment to Heroku (diff) | |
download | seven-wonders-deddd5ef5e8593009cd0e7dce699a459d497a727.tar.gz seven-wonders-deddd5ef5e8593009cd0e7dce699a459d497a727.tar.bz2 seven-wonders-deddd5ef5e8593009cd0e7dce699a459d497a727.zip |
Separate client and server errors in the ExceptionHandler
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/luxons/sevenwonders/errors/ErrorType.java | 4 | ||||
-rw-r--r-- | src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java | 24 |
2 files changed, 13 insertions, 15 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/errors/ErrorType.java b/src/main/java/org/luxons/sevenwonders/errors/ErrorType.java index a4a0f631..1cd18d09 100644 --- a/src/main/java/org/luxons/sevenwonders/errors/ErrorType.java +++ b/src/main/java/org/luxons/sevenwonders/errors/ErrorType.java @@ -1,7 +1,5 @@ package org.luxons.sevenwonders.errors; enum ErrorType { - USER, - VALIDATION, - INTERNAL + USER_INPUT, VALIDATION, CLIENT, SERVER } diff --git a/src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java b/src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java index 26a84ab2..628da4f8 100644 --- a/src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java +++ b/src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java @@ -37,13 +37,22 @@ public class ExceptionHandler { @MessageExceptionHandler @SendToUser("/queue/errors") + public UIError handleUserInputError(UserInputException exception) { + logger.error("Incorrect user input: " + exception.getMessage()); + String messageKey = exception.getMessageResourceKey(); + String message = messageSource.getMessage(messageKey, exception.getParams(), messageKey, Locale.US); + return new UIError(messageKey, message, ErrorType.USER_INPUT); + } + + @MessageExceptionHandler + @SendToUser("/queue/errors") public UIError handleValidationError(MethodArgumentNotValidException exception) { logger.error("Invalid input", exception); UIError uiError = new UIError(ERROR_CODE_VALIDATION, ERROR_MSG_VALIDATION, ErrorType.VALIDATION); BindingResult result = exception.getBindingResult(); if (result != null) { - List<ObjectError> errors = exception.getBindingResult().getAllErrors(); + List<ObjectError> errors = result.getAllErrors(); uiError.addDetails(errors); } return uiError; @@ -58,24 +67,15 @@ public class ExceptionHandler { @MessageExceptionHandler @SendToUser("/queue/errors") - public UIError handleGenericUserError(UserInputException exception) { - logger.error("Incorrect user input: " + exception.getMessage()); - String messageKey = exception.getMessageResourceKey(); - String message = messageSource.getMessage(messageKey, exception.getParams(), messageKey, Locale.US); - return new UIError(messageKey, message, ErrorType.USER); - } - - @MessageExceptionHandler - @SendToUser("/queue/errors") public UIError handleApiError(ApiMisuseException exception) { logger.error("Invalid API input", exception); - return new UIError(exception.getClass().getSimpleName(), exception.getMessage(), ErrorType.INTERNAL); + return new UIError(exception.getClass().getSimpleName(), exception.getMessage(), ErrorType.CLIENT); } @MessageExceptionHandler @SendToUser("/queue/errors") public UIError handleUnexpectedInternalError(Throwable exception) { logger.error("Uncaught exception thrown during message handling", exception); - return new UIError(exception.getClass().getSimpleName(), exception.getMessage(), ErrorType.INTERNAL); + return new UIError(exception.getClass().getSimpleName(), exception.getMessage(), ErrorType.SERVER); } } |