|
|
@@ -1,12 +1,15 @@
|
|
|
package com.kym.common.handler;
|
|
|
|
|
|
import cn.dev33.satoken.exception.NotLoginException;
|
|
|
+import cn.dev33.satoken.exception.NotPermissionException;
|
|
|
+import cn.dev33.satoken.exception.NotRoleException;
|
|
|
import com.kym.common.R;
|
|
|
import com.kym.common.exception.BaseException;
|
|
|
import com.kym.common.exception.BusinessException;
|
|
|
import com.kym.common.exception.EnPushException;
|
|
|
import jakarta.validation.ConstraintViolation;
|
|
|
import jakarta.validation.ConstraintViolationException;
|
|
|
+import jakarta.validation.ValidationException;
|
|
|
import org.apache.ibatis.jdbc.Null;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -21,6 +24,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.kym.common.constant.ResponseEnum.LOGIN_FAILED;
|
|
|
+import static com.kym.common.constant.ResponseEnum.NO_PERMISSION;
|
|
|
|
|
|
/**
|
|
|
* 全局异常处理
|
|
|
@@ -41,7 +45,7 @@ public class GlobalExceptionHandler {
|
|
|
@ExceptionHandler(value = BusinessException.class)
|
|
|
@ResponseBody
|
|
|
public R handleBusinessException(BaseException e) {
|
|
|
- LOGGER.error(e.getMessage(),e);
|
|
|
+ LOGGER.error(e.getMessage(), e);
|
|
|
return R.failed(e.getCode(), e.getMessage());
|
|
|
}
|
|
|
|
|
|
@@ -55,7 +59,7 @@ public class GlobalExceptionHandler {
|
|
|
@ResponseBody
|
|
|
public R<Null> handleBaseException(BaseException e) {
|
|
|
|
|
|
- LOGGER.error(e.getMessage(),e);
|
|
|
+ LOGGER.error(e.getMessage(), e);
|
|
|
return R.failed();
|
|
|
}
|
|
|
|
|
|
@@ -88,7 +92,7 @@ public class GlobalExceptionHandler {
|
|
|
} else {
|
|
|
message = NotLoginException.DEFAULT_MESSAGE;
|
|
|
}
|
|
|
- LOGGER.error("登录异常:"+ message,e);
|
|
|
+ LOGGER.error("登录异常:" + message, e);
|
|
|
return R.failed(LOGIN_FAILED.getCode(), message);
|
|
|
}
|
|
|
|
|
|
@@ -112,7 +116,7 @@ public class GlobalExceptionHandler {
|
|
|
* @param e
|
|
|
* @return
|
|
|
*/
|
|
|
- @ExceptionHandler(value = Exception.class)
|
|
|
+ @ExceptionHandler(value = {BindException.class, ValidationException.class})
|
|
|
public R handleValidatedException(Exception e) {
|
|
|
String message = "";
|
|
|
if (e instanceof MethodArgumentNotValidException) {
|
|
|
@@ -127,9 +131,15 @@ public class GlobalExceptionHandler {
|
|
|
message = ((BindException) e).getAllErrors().stream().map(ObjectError::getDefaultMessage)
|
|
|
.collect(Collectors.joining("; "));
|
|
|
}
|
|
|
- LOGGER.error(e.getMessage(),e);
|
|
|
+ LOGGER.error(e.getMessage(), e);
|
|
|
return R.failed(HttpStatus.BAD_REQUEST.value(), message);
|
|
|
}
|
|
|
|
|
|
+ @ExceptionHandler(value = {NotRoleException.class, NotPermissionException.class})
|
|
|
+ public R handlerException(Exception e) {
|
|
|
+ LOGGER.info(e.getMessage(), e);
|
|
|
+ return R.failed(NO_PERMISSION);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|