plusone-commons 修改了 BaseException
parent
1d4eadaefe
commit
0ea6867856
|
@ -13,7 +13,7 @@ public class BaseValidator<T> {
|
||||||
private final List<PropertyValidator<T, ?, ?>> propertyValidators = new ArrayList<>();
|
private final List<PropertyValidator<T, ?, ?>> propertyValidators = new ArrayList<>();
|
||||||
|
|
||||||
protected void withRule(final Predicate<T> rule, final String errorMessage) {
|
protected void withRule(final Predicate<T> rule, final String errorMessage) {
|
||||||
withRule(rule, () -> new InvalidInputException(errorMessage));
|
withRule(rule, () -> InvalidInputException.of(errorMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <E extends RuntimeException> void withRule(Predicate<T> rule, Supplier<E> exceptionBuilder) {
|
protected <E extends RuntimeException> void withRule(Predicate<T> rule, Supplier<E> exceptionBuilder) {
|
||||||
|
|
|
@ -11,29 +11,29 @@ public class InvalidInputException extends BaseException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 7956661913360059670L;
|
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);
|
super(code, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InvalidInputException(int code, Throwable cause) {
|
private InvalidInputException(String code, Throwable cause) {
|
||||||
super(code, cause);
|
super(code, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InvalidInputException(int code, String msg, Throwable cause) {
|
private InvalidInputException(String code, String msg, Throwable cause) {
|
||||||
super(code, msg, cause);
|
super(code, msg, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvalidInputException(String msg) {
|
public static InvalidInputException of(String msg) {
|
||||||
this(ERROR_CODE, msg);
|
return new InvalidInputException(ERROR_CODE, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvalidInputException(Throwable cause) {
|
public static InvalidInputException of(Throwable cause) {
|
||||||
this(ERROR_CODE, cause);
|
return new InvalidInputException(ERROR_CODE, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvalidInputException(String msg, Throwable cause) {
|
public static InvalidInputException of(String msg, Throwable cause) {
|
||||||
this(ERROR_CODE, msg, cause);
|
return new InvalidInputException(ERROR_CODE, msg, cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
|
||||||
// ===== equals =====
|
// ===== equals =====
|
||||||
|
|
||||||
public THIS equalsThat(Object that) {
|
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) {
|
public THIS equalsThat(Object that, String errMsg) {
|
||||||
|
@ -143,7 +143,7 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
|
||||||
}
|
}
|
||||||
|
|
||||||
static <V> Function<V, InvalidInputException> convertExceptionCreator(String errMsg) {
|
static <V> Function<V, InvalidInputException> convertExceptionCreator(String errMsg) {
|
||||||
return value -> new InvalidInputException(errMsg);
|
return value -> InvalidInputException.of(errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static <V, E extends RuntimeException> Function<V, E> convertExceptionCreator(
|
static <V, E extends RuntimeException> Function<V, E> convertExceptionCreator(
|
||||||
|
|
Loading…
Reference in New Issue