增加角色权限不足捕获

This commit is contained in:
张松
2025-02-12 17:40:17 +08:00
parent 8b83858f59
commit cf0ebfa8f4
2 changed files with 11 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package com.czg.exception;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import cn.dev33.satoken.exception.NotRoleException;
import cn.hutool.core.exceptions.ValidateException;
import com.czg.resp.CzgRespCode;
import com.czg.resp.CzgResult;
@@ -68,6 +69,14 @@ public class CzgControllerAdvice {
return CzgResult.failure(CzgRespCode.UN_PERMISSION);
}
@ResponseBody
@ExceptionHandler(value = NotRoleException.class)
@ResponseStatus(HttpStatus.OK)
public CzgResult<Object> notRoleErrorHandler(NotRoleException ex) {
setErrorLog(ex);
return CzgResult.failure(CzgRespCode.UN_ROLE);
}
@ResponseBody
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.OK)

View File

@@ -15,7 +15,8 @@ public enum CzgRespCode {
RECORD_EXISTED(602, "记录已存在"),
PARAM_ERROR(603, "参数错误"),
UNAUTHORIZED(401, "未授权"),
UN_PERMISSION(402, "无此接口权限"),;
UN_PERMISSION(402, "无此接口权限"),
UN_ROLE(403, "角色权限不足");
private final int code;
private final String msg;