diff --git a/src/main/java/xyz/zhouxy/plusone/validator/BaseValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/BaseValidator.java index ae00ac2..847a01d 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/BaseValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/BaseValidator.java @@ -13,7 +13,7 @@ public class BaseValidator { private final List> propertyValidators = new ArrayList<>(); protected void withRule(final Predicate rule, final String errorMessage) { - withRule(rule, () -> new InvalidInputException(errorMessage)); + withRule(rule, () -> InvalidInputException.of(errorMessage)); } protected void withRule(Predicate rule, Supplier exceptionBuilder) { diff --git a/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputException.java b/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputException.java index b8066cf..90310ce 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputException.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/InvalidInputException.java @@ -11,29 +11,29 @@ public class InvalidInputException extends BaseException { private static final long serialVersionUID = 7956661913360059670L; - public static final int ERROR_CODE = 4040200; + public static final String ERROR_CODE = "4040200"; - private InvalidInputException(int code, String msg) { + private InvalidInputException(String code, String msg) { super(code, msg); } - private InvalidInputException(int code, Throwable cause) { + private InvalidInputException(String code, Throwable cause) { super(code, cause); } - private InvalidInputException(int code, String msg, Throwable cause) { + private InvalidInputException(String code, String msg, Throwable cause) { super(code, msg, cause); } - public InvalidInputException(String msg) { - this(ERROR_CODE, msg); + public static InvalidInputException of(String msg) { + return new InvalidInputException(ERROR_CODE, msg); } - public InvalidInputException(Throwable cause) { - this(ERROR_CODE, cause); + public static InvalidInputException of(Throwable cause) { + return new InvalidInputException(ERROR_CODE, cause); } - public InvalidInputException(String msg, Throwable cause) { - this(ERROR_CODE, msg, cause); + public static InvalidInputException of(String msg, Throwable cause) { + return new InvalidInputException(ERROR_CODE, msg, cause); } } diff --git a/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java index a0298d2..2dafff3 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java @@ -69,7 +69,7 @@ abstract class PropertyValidator { // ===== equals ===== public THIS equalsThat(Object that) { - return equalsThat(that, value -> new InvalidInputException(String.format("(%s) 必须与 (%s) 相等", value, that))); + return equalsThat(that, value -> InvalidInputException.of(String.format("(%s) 必须与 (%s) 相等", value, that))); } public THIS equalsThat(Object that, String errMsg) { @@ -143,7 +143,7 @@ abstract class PropertyValidator { } static Function convertExceptionCreator(String errMsg) { - return value -> new InvalidInputException(errMsg); + return value -> InvalidInputException.of(errMsg); } static Function convertExceptionCreator(