cn.hippo4j.common.web.base.Results Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hippo4j-common Show documentation
Show all versions of hippo4j-common Show documentation
HIPPO4J、HIPPO4J-CORE 公共代码库.
package cn.hippo4j.common.web.base;
import cn.hippo4j.common.web.exception.ErrorCodeEnum;
import cn.hippo4j.common.web.exception.ServiceException;
/**
* Results.
*
* @author chen.ma
* @date 2021/3/19 16:12
*/
public final class Results {
public static Result success() {
return new Result()
.setCode(Result.SUCCESS_CODE);
}
public static Result success(T data) {
return new Result()
.setCode(Result.SUCCESS_CODE)
.setData(data);
}
public static Result failure(ServiceException serviceException) {
return new Result().setCode(ErrorCodeEnum.SERVICE_ERROR.getCode())
.setMessage(serviceException.getMessage());
}
public static Result failure(Throwable throwable) {
return new Result().setCode(ErrorCodeEnum.SERVICE_ERROR.getCode())
.setMessage(throwable.getMessage());
}
public static Result failure(String code, String message) {
return new Result()
.setCode(code)
.setMessage(message);
}
public static Result failure(ErrorCodeEnum errorCode) {
return new Result()
.setCode(errorCode.getCode())
.setMessage(errorCode.getMessage());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy