package com.usky.system.factory;

import com.usky.common.core.exception.FeignBadRequestException;
import com.usky.system.RemoteTenantService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yq
 * @date 2022/7/12 13:14
 */
@Component
public class RemoteTenantFallbackFactory implements FallbackFactory<RemoteTenantService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteTenantService create(Throwable throwable)
    {
        log.error("租户服务调用失败:{}", throwable.getMessage());
        return new RemoteTenantService()
        {

            @Override
            public List<Integer> getTenantIds() {
                throw new FeignBadRequestException(500,"获取租户异常"+throwable.getMessage());
            }

            @Override
            public Boolean validTenant(Integer id) {
                throw new FeignBadRequestException(500,"校验租户异常"+throwable.getMessage());
            }
        };
    }
}

