|
@@ -1,6 +1,8 @@
|
|
|
package com.fdkankan.gateway.exception;
|
|
|
|
|
|
|
|
|
+import cn.dev33.satoken.exception.*;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.constant.ServerCode;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import org.springframework.boot.autoconfigure.web.ErrorProperties;
|
|
@@ -11,6 +13,7 @@ import org.springframework.boot.web.reactive.error.ErrorAttributes;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.web.reactive.function.server.*;
|
|
|
+import sun.nio.cs.ext.MS874;
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
import java.util.HashMap;
|
|
@@ -29,16 +32,30 @@ public class JsonErrorWebExceptionHandler extends DefaultErrorWebExceptionHandle
|
|
|
protected Map<String, Object> getErrorAttributes(ServerRequest request, ErrorAttributeOptions options) {
|
|
|
|
|
|
// 这里其实可以根据异常类型进行定制化逻辑
|
|
|
- Throwable error = super.getError(request);
|
|
|
+ Throwable error = super.getError(request).getCause();
|
|
|
Map<String, Object> errorAttributes = new HashMap<>(8);
|
|
|
|
|
|
- if(error instanceof BusinessException){
|
|
|
- errorAttributes.put("code", ((BusinessException) error).getCode());
|
|
|
- errorAttributes.put("message", ((BusinessException) error).getMessage());
|
|
|
- }else{
|
|
|
- errorAttributes.put("code", ServerCode.SYSTEM_ERROR.code());
|
|
|
- errorAttributes.put("message", ServerCode.SYSTEM_ERROR.message());
|
|
|
+ Integer code = ServerCode.SYSTEM_ERROR.code();
|
|
|
+ String message = ServerCode.SYSTEM_ERROR.message();
|
|
|
+ if(error instanceof NotLoginException){
|
|
|
+ code = 201;
|
|
|
+ message = "请重新登录";
|
|
|
+ }else if(error instanceof NotRoleException){
|
|
|
+ code = 202;
|
|
|
+ message = "无此角色:" + ((NotRoleException) error).getRole();
|
|
|
+ }else if(error instanceof NotPermissionException){
|
|
|
+ code = 201;
|
|
|
+ message = "无此权限:" + ((NotPermissionException) error).getPermission();
|
|
|
+ }else if(error instanceof DisableLoginException){
|
|
|
+ code = 201;
|
|
|
+ message = "账号被封禁:" + ((DisableLoginException) error).getDisableTime() + "秒后解封";
|
|
|
+ } else if(error instanceof BusinessException){
|
|
|
+ code = ((BusinessException) error).getCode();
|
|
|
+ message = error.getMessage();
|
|
|
}
|
|
|
+
|
|
|
+ errorAttributes.put("code", code);
|
|
|
+ errorAttributes.put("message", message);
|
|
|
errorAttributes.put("method", request.methodName());
|
|
|
errorAttributes.put("path", request.path());
|
|
|
errorAttributes.put("timestamp", Calendar.getInstance().getTimeInMillis());
|