提交 809a91a0 编写于 作者: N NAVER

🐛 Fixing a bug. #I1GTO8 接口没有权限提示不够友好 bug

上级 ca38a27a
......@@ -2,6 +2,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.pig4cloud.pig.common.core.config.JacksonConfig,\
com.pig4cloud.pig.common.core.config.RedisTemplateConfig,\
com.pig4cloud.pig.common.core.config.RestTemplateConfig,\
com.pig4cloud.pig.common.core.exception.GlobalExceptionHandler,\
com.pig4cloud.pig.common.core.util.SpringContextHolder,\
com.pig4cloud.pig.common.core.mybatis.WebMvcConfig
......@@ -16,11 +16,12 @@
*
*/
package com.pig4cloud.pig.common.core.exception;
package com.pig4cloud.pig.common.security.component;
import com.pig4cloud.pig.common.core.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
......@@ -37,7 +38,7 @@ import java.util.List;
*/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
public class GlobalExceptionHandlerResolver {
/**
* 全局异常.
*
......@@ -51,6 +52,19 @@ public class GlobalExceptionHandler {
return R.failed(e);
}
/**
* AccessDeniedException
*
* @param e the e
* @return R
*/
@ExceptionHandler(AccessDeniedException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
public R handleAccessDeniedException(AccessDeniedException e) {
log.warn("拒绝授权异常信息 ex={}", e.getLocalizedMessage());
return R.failed(e.getLocalizedMessage());
}
/**
* validation Exception (以json形式传参)
*
......@@ -64,6 +78,7 @@ public class GlobalExceptionHandler {
log.warn(fieldErrors.get(0).getDefaultMessage());
return R.failed(fieldErrors.get(0).getDefaultMessage());
}
/**
* validation Exception (以form-data形式传参)
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册