|
@@ -1,6 +1,9 @@
|
|
|
package com.fdkankan.manage.config;
|
|
|
|
|
|
import cn.dev33.satoken.context.SaHolder;
|
|
|
+import cn.dev33.satoken.exception.NotLoginException;
|
|
|
+import cn.dev33.satoken.exception.NotPermissionException;
|
|
|
+import cn.dev33.satoken.exception.NotRoleException;
|
|
|
import cn.dev33.satoken.filter.SaServletFilter;
|
|
|
import cn.dev33.satoken.jwt.StpLogicJwtForMixin;
|
|
|
import cn.dev33.satoken.router.SaRouter;
|
|
@@ -62,7 +65,27 @@ public class SaTokenConfigure {
|
|
|
.setError(e -> {
|
|
|
System.out.println("---------- 进入Sa-Token异常处理 -----------");
|
|
|
SaHolder.getResponse().setHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
- return JSONObject.toJSONString(ResultData.error(-1,e.getMessage()));
|
|
|
+ ResultData aj = null;
|
|
|
+ if (e instanceof NotLoginException) { // 如果是未登录异常
|
|
|
+ NotLoginException ee = (NotLoginException) e;
|
|
|
+ aj = ResultData.error(ErrorCode.USER_NOT_LOGIN);
|
|
|
+ }
|
|
|
+ else if(e instanceof NotRoleException) { // 如果是角色异常
|
|
|
+ NotRoleException ee = (NotRoleException) e;
|
|
|
+ aj = ResultData.error(4010,"无此角色:" + ee.getRole());
|
|
|
+ }
|
|
|
+ else if(e instanceof NotPermissionException) { // 如果是权限异常
|
|
|
+ NotPermissionException ee = (NotPermissionException) e;
|
|
|
+ aj = ResultData.error(4011,"无此权限:" + ee.getPermission());
|
|
|
+ }
|
|
|
+ else if(e instanceof BusinessException) { // 如果是权限异常
|
|
|
+ BusinessException ee = (BusinessException) e;
|
|
|
+ aj = ResultData.error(ee.getCode(),ee.getMessage());
|
|
|
+ }
|
|
|
+ else { // 普通异常, 输出:500 + 异常信息
|
|
|
+ aj = ResultData.error(500,e.getMessage());
|
|
|
+ }
|
|
|
+ return JSONObject.toJSONString(aj);
|
|
|
})
|
|
|
// 前置函数:在每次认证函数之前执行
|
|
|
.setBeforeAuth(r -> {
|