ÎļþÃû´Ó ruoyi-common/ruoyi-common-security/src/main/java/org/dromara/common/security/handler/GlobalExceptionHandler.java ÐÞ¸Ä |
| | |
| | | package org.dromara.common.security.handler; |
| | | package org.dromara.common.web.handler; |
| | | |
| | | import cn.dev33.satoken.exception.NotLoginException; |
| | | import cn.dev33.satoken.exception.NotPermissionException; |
| | | import cn.dev33.satoken.exception.NotRoleException; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.http.HttpStatus; |
| | | import jakarta.servlet.http.HttpServletRequest; |
| | |
| | | @Slf4j |
| | | @RestControllerAdvice |
| | | public class GlobalExceptionHandler { |
| | | |
| | | /** |
| | | * æéç å¼å¸¸ |
| | | */ |
| | | @ExceptionHandler(NotPermissionException.class) |
| | | public R<Void> handleNotPermissionException(NotPermissionException e, HttpServletRequest request) { |
| | | String requestURI = request.getRequestURI(); |
| | | log.error("请æ±å°å'{}',æéç æ ¡éªå¤±è´¥'{}'", requestURI, e.getMessage()); |
| | | return R.fail(HttpStatus.HTTP_FORBIDDEN, "没æè®¿é®æéï¼è¯·è系管çåææ"); |
| | | } |
| | | |
| | | /** |
| | | * è§è²æéå¼å¸¸ |
| | | */ |
| | | @ExceptionHandler(NotRoleException.class) |
| | | public R<Void> handleNotRoleException(NotRoleException e, HttpServletRequest request) { |
| | | String requestURI = request.getRequestURI(); |
| | | log.error("请æ±å°å'{}',è§è²æéæ ¡éªå¤±è´¥'{}'", requestURI, e.getMessage()); |
| | | return R.fail(HttpStatus.HTTP_FORBIDDEN, "没æè®¿é®æéï¼è¯·è系管çåææ"); |
| | | } |
| | | |
| | | /** |
| | | * 认è¯å¤±è´¥ |
| | | */ |
| | | @ExceptionHandler(NotLoginException.class) |
| | | public R<Void> handleNotLoginException(NotLoginException e, HttpServletRequest request) { |
| | | String requestURI = request.getRequestURI(); |
| | | log.error("请æ±å°å'{}',认è¯å¤±è´¥'{}',æ æ³è®¿é®ç³»ç»èµæº", requestURI, e.getMessage()); |
| | | return R.fail(HttpStatus.HTTP_UNAUTHORIZED, "认è¯å¤±è´¥ï¼æ æ³è®¿é®ç³»ç»èµæº"); |
| | | } |
| | | |
| | | /** |
| | | * è¯·æ±æ¹å¼ä¸æ¯æ |