package com.yanzhu.system.api.factory;

import com.yanzhu.common.core.domain.R;
import com.yanzhu.system.api.RemoteRoleService;
import com.yanzhu.system.api.domain.SysRole;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 角色服务降级处理
 *
 * @author JiangYuQi
 */
@Component
public class RemoteRoleFallbackFactory implements FallbackFactory<RemoteRoleService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteRoleFallbackFactory.class);

    @Override
    public RemoteRoleService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteRoleService() {
            @Override
            public R<SysRole> getRoleInfo(Long roleId, String source) {
                return R.fail("获取角色失败:" + throwable.getMessage());
            }
        };
    }
}
