|
|
@@ -1,16 +1,17 @@
|
|
|
package seecoder.devcloud.web.infrastructure;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
+import org.apache.http.HttpStatus;
|
|
|
+import org.springframework.validation.BindException;
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
-import seecoder.devcloud.common.exceptions.AccessDeniedException;
|
|
|
-import seecoder.devcloud.common.exceptions.ConflictException;
|
|
|
import seecoder.devcloud.common.exceptions.ServiceException;
|
|
|
import seecoder.devcloud.web.infrastructure.security.TokenExpiredException;
|
|
|
import seecoder.devcloud.web.model.vo.Response;
|
|
|
|
|
|
+import javax.validation.ConstraintViolationException;
|
|
|
+
|
|
|
/**
|
|
|
* @author PuHong Weng
|
|
|
* @date 2021/3/5
|
|
|
@@ -20,6 +21,22 @@ import seecoder.devcloud.web.model.vo.Response;
|
|
|
@Slf4j
|
|
|
public class GlobalExceptionHandler {
|
|
|
|
|
|
+ //***************************validation参数异常的捕获**************
|
|
|
+
|
|
|
+ @ExceptionHandler(value = BindException.class)
|
|
|
+ @ResponseBody
|
|
|
+ public Response handleResourceBindException(BindException e) {
|
|
|
+ return Response.buildFailure(HttpStatus.SC_BAD_REQUEST, e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ @ExceptionHandler(value = ConstraintViolationException.class)
|
|
|
+ @ResponseBody
|
|
|
+ public Response handleResourceConstraintViolationException(ConstraintViolationException e) {
|
|
|
+ return Response.buildFailure(HttpStatus.SC_BAD_REQUEST, e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ //***************************业务异常的捕获**************
|
|
|
+
|
|
|
@ExceptionHandler(ServiceException.class)
|
|
|
@ResponseBody
|
|
|
public Response serviceExceptionHandler(ServiceException e){
|