Browse Source

fix 用户异常

jay 2 năm trước cách đây
mục cha
commit
a2b3dfca87

+ 10 - 10
iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/BaseException.java

@@ -40,29 +40,29 @@ public class BaseException extends RuntimeException {
     /**
      * 错误消息
      */
-    private String defaultMessage;
+    private String message;
 
-    public BaseException(String module, String code, Object[] args, String defaultMessage) {
+    public BaseException(String module, String code, Object[] args, String message) {
         this.module = module;
         this.code = code;
         this.args = args;
-        this.defaultMessage = defaultMessage;
+        this.message = message;
     }
 
-    public BaseException(String module, String code, Object[] args) {
-        this(module, code, args, null);
+    public BaseException(String module, String code, String message) {
+        this(module, code, null, message);
     }
 
-    public BaseException(String module, String defaultMessage) {
-        this(module, null, null, defaultMessage);
+    public BaseException(String module, String message) {
+        this(module, null, null, message);
     }
 
     public BaseException(String code, Object[] args) {
         this(null, code, args, null);
     }
 
-    public BaseException(String defaultMessage) {
-        this(null, null, null, defaultMessage);
+    public BaseException(String message) {
+        this(null, null, null, message);
     }
 
     @Override
@@ -72,7 +72,7 @@ public class BaseException extends RuntimeException {
             message = MessageUtils.message(code, args);
         }
         if (message == null) {
-            message = defaultMessage;
+            message = message;
         }
         return message;
     }

+ 7 - 4
iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/user/UserException.java

@@ -11,6 +11,7 @@ package cc.iotkit.common.exception.user;
 
 import cc.iotkit.common.enums.ErrCode;
 import cc.iotkit.common.exception.BaseException;
+import cc.iotkit.common.exception.BizException;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
@@ -20,7 +21,7 @@ import lombok.NoArgsConstructor;
 @Data
 @NoArgsConstructor
 @AllArgsConstructor
-public class UserException extends BaseException {
+public class UserException extends BizException {
 
     /**
      * 所属模块
@@ -30,15 +31,17 @@ public class UserException extends BaseException {
     /**
      * 错误码
      */
-    private String code;
+    private Integer code;
 
     /**
      * 错误消息
      */
     private String message;
 
-    public UserException(String code, Object... args) {
-        super("user", code, args, null);
+    public UserException(String message) {
+        super(  message);
+        this.code = ErrCode.SYSTEM_EXCEPTION.getKey();
+
     }
 
 }

+ 11 - 9
iot-starter/src/main/java/cc/iotkit/web/service/SysLoginService.java

@@ -236,10 +236,10 @@ public class SysLoginService {
 
         if (ObjectUtil.isNull(user)) {
             log.info("登录用户:{} 不存在.", username);
-            throw new UserException("user.not.exists", username);
+            throw new UserException("登录用户不存在");
         } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
             log.info("登录用户:{} 已被停用.", username);
-            throw new UserException("user.blocked", username);
+            throw new UserException("用户被停用");
         }
         if (TenantHelper.isEnable()) {
             SysUser sysUser = userData.selectTenantUserByUserName(username, tenantId);
@@ -260,10 +260,10 @@ public class SysLoginService {
         SysUser user = userData.findOneByCondition(query);
         if (ObjectUtil.isNull(user)) {
             log.info("登录用户:{} 不存在.", phonenumber);
-            throw new UserException("user.not.exists", phonenumber);
+            throw new UserException("登录用户不存在");
         } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
             log.info("登录用户:{} 已被停用.", phonenumber);
-            throw new UserException("user.blocked", phonenumber);
+            throw new UserException("用户被停用");
         }
 
         if (TenantHelper.isEnable()) {
@@ -285,10 +285,10 @@ public class SysLoginService {
 
         if (ObjectUtil.isNull(user)) {
             log.info("登录用户:{} 不存在.", email);
-            throw new UserException("user.not.exists", email);
+            throw new UserException("用户不存在");
         } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
             log.info("登录用户:{} 已被停用.", email);
-            throw new UserException("user.blocked", email);
+            throw new UserException("用户被停用");
         }
         if (TenantHelper.isEnable()) {
             SysUser sysUser = userData.selectTenantUserByEmail(email, tenantId);
@@ -357,7 +357,7 @@ public class SysLoginService {
         // 锁定时间内登录 则踢出
         if (ObjectUtil.isNotNull(errorNumber) && errorNumber.equals(maxRetryCount)) {
             recordLogininfor(tenantId, username, loginFail, MessageUtils.message(loginType.getRetryLimitExceed(), maxRetryCount, lockTime));
-            throw new UserException(loginType.getRetryLimitExceed(), maxRetryCount, lockTime);
+            throw new UserException("重试达到最大限制" );
         }
 
         if (supplier.get()) {
@@ -367,12 +367,14 @@ public class SysLoginService {
             if (errorNumber.equals(maxRetryCount)) {
                 RedisUtils.setCacheObject(errorKey, errorNumber, Duration.ofMinutes(lockTime));
                 recordLogininfor(tenantId, username, loginFail, MessageUtils.message(loginType.getRetryLimitExceed(), maxRetryCount, lockTime));
-                throw new UserException(loginType.getRetryLimitExceed(), maxRetryCount, lockTime);
+                throw new UserException( "重试达到最大限制" );
+
             } else {
                 // 未达到规定错误次数 则递增
                 RedisUtils.setCacheObject(errorKey, errorNumber);
                 recordLogininfor(tenantId, username, loginFail, MessageUtils.message(loginType.getRetryLimitCount(), errorNumber));
-                throw new UserException(loginType.getRetryLimitCount(), errorNumber);
+                throw new UserException( String.format("错误次数:%s", errorNumber) );
+
             }
         }
 

+ 2 - 2
iot-starter/src/main/java/cc/iotkit/web/service/SysRegisterService.java

@@ -51,11 +51,11 @@ public class SysRegisterService {
         sysUser.setUserType(userType);
 
         if (!userService.checkUserNameUnique(sysUser)) {
-            throw new UserException("user.register.save.error", username);
+            throw new UserException( username);
         }
         boolean regFlag = userService.registerUser(sysUser, tenantId);
         if (!regFlag) {
-            throw new UserException("user.register.error");
+            throw new UserException( "注册失败" );
         }
         recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success"));
     }