diff --git a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java index fd05fdb..4848072 100644 --- a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java +++ b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/AllExceptionHandlerConfig.java @@ -4,6 +4,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import xyz.zhouxy.plusone.constant.ErrorCodeConsts; import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler.ExceptionInfoHolder; /** @@ -15,6 +16,6 @@ public class AllExceptionHandlerConfig { @Bean AllExceptionHandler getAllExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { - return new AllExceptionHandler(exceptionInfoHolder); + return new AllExceptionHandler(ErrorCodeConsts.DEFAULT_ERROR_CODE, exceptionInfoHolder); } } diff --git a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java index af53870..263d35d 100644 --- a/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java +++ b/plusone-basic/plusone-basic-application/src/main/java/xyz/zhouxy/plusone/exception/handler/DefaultExceptionHandler.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import lombok.extern.slf4j.Slf4j; +import xyz.zhouxy.plusone.constant.ErrorCodeConsts; import xyz.zhouxy.plusone.util.RestfulResult; /** @@ -42,7 +43,7 @@ import xyz.zhouxy.plusone.util.RestfulResult; public class DefaultExceptionHandler extends BaseExceptionHandler { public DefaultExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { - super(exceptionInfoHolder); + super(ErrorCodeConsts.DEFAULT_ERROR_CODE, exceptionInfoHolder); set(IllegalArgumentException.class, 4010000, "格式错误", HttpStatus.FORBIDDEN); set(DataAccessException.class, 6030000, "数据库错误", HttpStatus.INTERNAL_SERVER_ERROR, true); set(MethodArgumentNotValidException.class, diff --git a/plusone-basic/plusone-basic-common/pom.xml b/plusone-basic/plusone-basic-common/pom.xml index 828e5b0..d3d662d 100644 --- a/plusone-basic/plusone-basic-common/pom.xml +++ b/plusone-basic/plusone-basic-common/pom.xml @@ -39,7 +39,7 @@ xyz.zhouxy.plusone plusone-exception-handler - 0.0.3-SNAPSHOT + 0.0.4-SNAPSHOT diff --git a/plusone-basic/plusone-basic-common/src/main/java/xyz/zhouxy/plusone/constant/ErrorCodeConsts.java b/plusone-basic/plusone-basic-common/src/main/java/xyz/zhouxy/plusone/constant/ErrorCodeConsts.java new file mode 100644 index 0000000..f1958f9 --- /dev/null +++ b/plusone-basic/plusone-basic-common/src/main/java/xyz/zhouxy/plusone/constant/ErrorCodeConsts.java @@ -0,0 +1,5 @@ +package xyz.zhouxy.plusone.constant; + +public class ErrorCodeConsts { + public static final int DEFAULT_ERROR_CODE = 9999999; +} diff --git a/plusone-start/src/main/java/xyz/zhouxy/plusone/TestController.java b/plusone-start/src/main/java/xyz/zhouxy/plusone/TestController.java new file mode 100644 index 0000000..4e1ea42 --- /dev/null +++ b/plusone-start/src/main/java/xyz/zhouxy/plusone/TestController.java @@ -0,0 +1,12 @@ +package xyz.zhouxy.plusone; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TestController { + @RequestMapping("/test") + public String test() throws Exception { + throw new Exception(); + } +} diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java index 79d91bf..b83cafb 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/exception/handler/SaTokenExceptionHandler.java @@ -14,6 +14,7 @@ import cn.dev33.satoken.exception.NotRoleException; import cn.dev33.satoken.exception.NotSafeException; import cn.dev33.satoken.exception.SaTokenException; import lombok.extern.slf4j.Slf4j; +import xyz.zhouxy.plusone.constant.ErrorCodeConsts; import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler; import xyz.zhouxy.plusone.util.RestfulResult; @@ -27,7 +28,7 @@ import xyz.zhouxy.plusone.util.RestfulResult; public class SaTokenExceptionHandler extends BaseExceptionHandler { public SaTokenExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) { - super(exceptionInfoHolder); + super(ErrorCodeConsts.DEFAULT_ERROR_CODE, exceptionInfoHolder); set(NotPermissionException.class, 4030103, "会话未能通过权限认证", HttpStatus.FORBIDDEN); set(NotRoleException.class, 4030103, "会话未能通过角色认证", HttpStatus.FORBIDDEN); set(DisableServiceException.class, 4030202, "账号指定服务已被封禁", HttpStatus.FORBIDDEN); diff --git a/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java b/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java index c0ac1bb..38d95b8 100644 --- a/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java +++ b/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java @@ -4,6 +4,7 @@ import javax.annotation.Nonnull; import cn.hutool.core.util.RandomUtil; import cn.hutool.crypto.digest.DigestUtil; +import xyz.zhouxy.plusone.constant.ErrorCodeConsts; import xyz.zhouxy.plusone.exception.PlusoneException; /** @@ -30,7 +31,7 @@ public final class PasswordUtil { + salt.substring(1); String sha512Hex = DigestUtil.sha512Hex(passwordWithSalt); if (sha512Hex == null) { - throw new PlusoneException(9999999, "未知错误:哈希加密失败!"); + throw new PlusoneException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:哈希加密失败!"); } return sha512Hex; } diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java index 5388195..596e5a7 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java @@ -7,6 +7,7 @@ import javax.annotation.Nonnull; import org.springframework.util.Assert; +import xyz.zhouxy.plusone.constant.ErrorCodeConsts; import xyz.zhouxy.plusone.constant.RegexConsts; import xyz.zhouxy.plusone.domain.IValueObject; import xyz.zhouxy.plusone.exception.PlusoneException; @@ -36,7 +37,7 @@ public class Password implements IValueObject { } var salt = PasswordUtil.generateRandomSalt(); if (salt == null) { - throw new PlusoneException(9999999, "未知错误:生成随机盐失败"); + throw new PlusoneException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:生成随机盐失败"); } this.saltVal = salt; this.passwordVal = PasswordUtil.hashPassword(password, salt);