feign工具类

34 阅读1分钟

feign工具类


@Slf4j  
public abstract class FeignHelper {  
  
public static <T> T request(Callable<ResponseResult<T>> task,  
    Consumer<ResponseResult<T>> resultCallback,  
    Consumer<Exception> errorCallBack){  
        try {  
            ResponseResult<T> call = task.call();  
            resultCallback.accept(call);  
            if (!HttpCode.SUCCESS.equals(call.getCode())){  
                throw new BizException(SERVER_ERROR.getCode(),call.getMsg());  
            }  
            return call.getData();  
        }catch (Exception e){  
            errorCallBack.accept(e);  
            if (e instanceof BizException){  
                BizException be = (BizException) e;  
                throw be;  
            }  
        throw new BizException(REMOTE_ERROR.getCode(),e.getMessage());  
        }  
    }  
}