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

com.jdkhome.blzo.ex.consul.RpcTools Maven / Gradle / Ivy

There is a newer version: 0.3.3.1.RELEASE
Show newest version
package com.jdkhome.blzo.ex.consul;

import com.jdkhome.blzo.ex.basic.enums.BasicResponseError;
import com.jdkhome.blzo.ex.basic.exception.ServiceException;
import com.jdkhome.blzo.ex.basic.pojo.ApiResponse;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RpcTools {

    /**
     * 校验rpc的返回码
     *
     * @param apiResponse
     */
    public static void check(ApiResponse apiResponse) {

        if (!BasicResponseError.SUCCESS.getCode().equals(apiResponse.getCode())) {

            throw new ServiceException(apiResponse.getCode(), apiResponse.getMsg(), "[来自RPC]" + apiResponse.getDebug(),
                    BasicResponseError.UPSTREAM_ERROR);
        }
    }

    /**
     * 校验并获取请求内容
     *
     * @param apiResponse
     * @param 
     * @return
     */
    public static  T get(ApiResponse apiResponse) {
        if (!BasicResponseError.SUCCESS.getCode().equals(apiResponse.getCode())) {
            throw new ServiceException(apiResponse.getCode(), apiResponse.getMsg(), "[来自RPC]" + apiResponse.getDebug(),
                    BasicResponseError.UPSTREAM_ERROR);
        }
        return apiResponse.getData();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy