All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.hippo4j.common.web.base.Results Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
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