summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/luxons/sevenwonders/errors/ErrorType.java4
-rw-r--r--src/main/java/org/luxons/sevenwonders/errors/ExceptionHandler.java24
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);
}
}
bgstack15