fix TimiX multilingual
This commit is contained in:
@ -15,9 +15,9 @@ public class TimiError extends AssertionError implements LanguageMsgMapping<Timi
|
||||
/** 代码 */
|
||||
protected final TimiCode code;
|
||||
|
||||
protected String msgKey;
|
||||
protected transient String msgKey;
|
||||
|
||||
protected Map<String, Object> msgArgs;
|
||||
protected transient Map<String, Object> msgArgs;
|
||||
|
||||
/** @param code 代码 */
|
||||
public TimiError(TimiCode code) {
|
||||
@ -45,7 +45,7 @@ public class TimiError extends AssertionError implements LanguageMsgMapping<Timi
|
||||
}
|
||||
|
||||
public TimiResponse<?> toResponse() {
|
||||
return new TimiResponse<>(code).msg(getMessage()).msgKey(msgKey);
|
||||
return new TimiResponse<>(code).msg(getMessage()).msgKey(msgKey, msgArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -17,9 +17,9 @@ public class TimiException extends RuntimeException implements LanguageMsgMappin
|
||||
/** 代码 */
|
||||
protected final TimiCode code;
|
||||
|
||||
protected String msgKey;
|
||||
protected transient String msgKey;
|
||||
|
||||
protected Map<String, Object> msgArgs;
|
||||
protected transient Map<String, Object> msgArgs;
|
||||
|
||||
/** @param code 代码 */
|
||||
public TimiException(TimiCode code) {
|
||||
@ -58,7 +58,7 @@ public class TimiException extends RuntimeException implements LanguageMsgMappin
|
||||
}
|
||||
|
||||
public TimiResponse<?> toResponse() {
|
||||
return new TimiResponse<>(code).msg(getMessage()).msgKey(msgKey);
|
||||
return new TimiResponse<>(code).msg(getMessage()).msgKey(msgKey, msgArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -116,12 +116,25 @@ public class TimiException extends RuntimeException implements LanguageMsgMappin
|
||||
return t;
|
||||
}
|
||||
|
||||
public static <T> T required(T t, String message, String msgKey) {
|
||||
if (TimiJava.isEmpty(t)) {
|
||||
throw new TimiException(TimiCode.ARG_MISS, message).msgKey(msgKey);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public static <T> void requiredNull(T t, String message) throws TimiException {
|
||||
if (t != null) {
|
||||
throw new TimiException(TimiCode.ERROR, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void requiredNull(T t, String message, String msgKey) throws TimiException {
|
||||
if (t != null) {
|
||||
throw new TimiException(TimiCode.ERROR, message).msgKey(msgKey);
|
||||
}
|
||||
}
|
||||
|
||||
public static void requiredTrue(boolean bool, String message) throws TimiException {
|
||||
if (bool) {
|
||||
return;
|
||||
@ -129,11 +142,11 @@ public class TimiException extends RuntimeException implements LanguageMsgMappin
|
||||
throw new TimiException(TimiCode.ERROR, message);
|
||||
}
|
||||
|
||||
public static void requiredFalse(boolean bool, String message) throws TimiException {
|
||||
if (!bool) {
|
||||
public static void requiredTrue(boolean bool, String message, String msgKey) throws TimiException {
|
||||
if (bool) {
|
||||
return;
|
||||
}
|
||||
throw new TimiException(TimiCode.ERROR, message);
|
||||
throw new TimiException(TimiCode.ERROR, message).msgKey(msgKey);
|
||||
}
|
||||
|
||||
public static void requiredTrue(CallbackReturn<Boolean> callback, String message) throws TimiException {
|
||||
@ -144,11 +157,11 @@ public class TimiException extends RuntimeException implements LanguageMsgMappin
|
||||
throw new TimiException(TimiCode.ERROR, message);
|
||||
}
|
||||
|
||||
public static void requiredFalse(CallbackReturn<Boolean> callback, String message) throws TimiException {
|
||||
public static void requiredTrue(CallbackReturn<Boolean> callback, String message, String msgKey) throws TimiException {
|
||||
TimiException.required(callback, "not found callback");
|
||||
if (!callback.handler()) {
|
||||
if (callback.handler()) {
|
||||
return;
|
||||
}
|
||||
throw new TimiException(TimiCode.ERROR, message);
|
||||
throw new TimiException(TimiCode.ERROR, message).msgKey(msgKey);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,9 +19,9 @@ public class TimiResponse<T> implements Serializable, LanguageMsgMapping<TimiRes
|
||||
/** 消息 */
|
||||
protected String msg;
|
||||
|
||||
protected String msgKey;
|
||||
protected transient String msgKey;
|
||||
|
||||
protected Map<String, Object> msgArgs;
|
||||
protected transient Map<String, Object> msgArgs;
|
||||
|
||||
/** 数据体 */
|
||||
protected T data;
|
||||
|
||||
Reference in New Issue
Block a user