|
@@ -0,0 +1,30 @@
|
|
|
|
+package org.hsweb.web.controller;
|
|
|
|
+
|
|
|
|
+import org.hsweb.web.core.exception.NotFoundException;
|
|
|
|
+import org.hsweb.web.core.exception.ValidationException;
|
|
|
|
+import org.hsweb.web.core.message.ResponseMessage;
|
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
|
+import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
|
+import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
|
+
|
|
|
|
+@ControllerAdvice
|
|
|
|
+public class ControllerExceptionTranslator {
|
|
|
|
+
|
|
|
|
+ @ExceptionHandler(ValidationException.class)
|
|
|
|
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
+ @ResponseBody
|
|
|
|
+ ResponseMessage handleException(ValidationException exception) {
|
|
|
|
+ return ResponseMessage.error(exception.getMessage(), 400);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @ExceptionHandler(NotFoundException.class)
|
|
|
|
+ @ResponseStatus(HttpStatus.NOT_FOUND)
|
|
|
|
+ @ResponseBody
|
|
|
|
+ ResponseMessage handleException(NotFoundException exception) {
|
|
|
|
+ return ResponseMessage.error(exception.getMessage(), 404);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|