package com.microservices.system.api.utils;

import com.microservices.common.core.domain.R;
import com.microservices.common.core.exception.ServiceException;
import com.microservices.common.core.utils.StringUtils;
import feign.Response;

/**
 * @author otto
 */
public class FeignUtils {
    public static <T> T getReturnData(R<T> result) {
        if (StringUtils.isNull(result)) {
            return null;
        }

        if (R.FAIL == result.getCode()) {
            throw new ServiceException(result.getMsg());
        }
        return result.getData();
    }

    public static Boolean isSuccess(Response response) {
        return response != null && response.status() >= 200 && response.status() < 300;
    }
}
