|
|
@@ -1,5 +1,6 @@
|
|
|
package com.cyksj.web;
|
|
|
|
|
|
+import cn.dev33.satoken.exception.NotLoginException;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayApiCode;
|
|
|
@@ -30,6 +31,8 @@ public class GlobalExceptionHandler {
|
|
|
@Autowired
|
|
|
protected HttpServletRequest request;
|
|
|
|
|
|
+ private final static List<String> token = List.of("token无效", "token已过期");
|
|
|
+
|
|
|
@ExceptionHandler(value = {Exception.class})
|
|
|
public Result<String> handleNoteException(Exception e) {
|
|
|
StringBuilder builder = new StringBuilder(32);
|
|
|
@@ -48,8 +51,22 @@ public class GlobalExceptionHandler {
|
|
|
|
|
|
String message = e.getMessage();
|
|
|
String value = builder.toString();
|
|
|
+ GatewayApiCode apiCode = null;
|
|
|
+ if (e instanceof NotLoginException) {
|
|
|
+ //未登录
|
|
|
+ NotLoginException ee = (NotLoginException) e;
|
|
|
+ if (token.contains(ee.getMessage())) {
|
|
|
+ apiCode = GatewayApiCode.CMS_TOKEN_VALID;
|
|
|
+ } else if ("token已被踢下线".equals(ee.getMessage())) {
|
|
|
+ apiCode = GatewayApiCode.CMS_TOKEN_OUT_LINE;
|
|
|
+ } else {
|
|
|
+ apiCode = GatewayApiCode.CMS_USER_NO_LOGIN;
|
|
|
+ }
|
|
|
+ }
|
|
|
log.error("全局错误处理: \n Cause: {} \n Value: {}", message, value);
|
|
|
-
|
|
|
+ if (apiCode != null) {
|
|
|
+ return GatewayResponse.FAIL.newBuilder().buildGatewayCode(apiCode).toResult();
|
|
|
+ }
|
|
|
return GatewayResponse.FAIL.newBuilder().setMsg(message).toResult(value);
|
|
|
}
|
|
|
|