parent
87b75e18f0
commit
9b1e01fa93
|
@ -1,11 +1,12 @@
|
||||||
package cn.iocoder.yudao.framework.common.pojo;
|
package cn.iocoder.yudao.framework.common.pojo;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||||
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
|
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
|
||||||
|
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -49,13 +50,21 @@ public class CommonResult<T> implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> CommonResult<T> error(Integer code, String message) {
|
public static <T> CommonResult<T> error(Integer code, String message) {
|
||||||
Assert.isTrue(!GlobalErrorCodeConstants.SUCCESS.getCode().equals(code), "code 必须是错误的!");
|
Assert.notEquals(GlobalErrorCodeConstants.SUCCESS.getCode(), code, "code 必须是错误的!");
|
||||||
CommonResult<T> result = new CommonResult<>();
|
CommonResult<T> result = new CommonResult<>();
|
||||||
result.code = code;
|
result.code = code;
|
||||||
result.msg = message;
|
result.msg = message;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> CommonResult<T> error(ErrorCode errorCode, Object... params) {
|
||||||
|
Assert.notEquals(GlobalErrorCodeConstants.SUCCESS.getCode(), errorCode.getCode(), "code 必须是错误的!");
|
||||||
|
CommonResult<T> result = new CommonResult<>();
|
||||||
|
result.code = errorCode.getCode();
|
||||||
|
result.msg = ServiceExceptionUtil.doFormat(errorCode.getCode(), errorCode.getMsg(), params);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> CommonResult<T> error(ErrorCode errorCode) {
|
public static <T> CommonResult<T> error(ErrorCode errorCode) {
|
||||||
return error(errorCode.getCode(), errorCode.getMsg());
|
return error(errorCode.getCode(), errorCode.getMsg());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue