package com.jeeplus.common.factory;

import com.jeeplus.common.feign.IFileApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 文件服务降级处理
 *
 * @author jeeplus
 */

@Slf4j
@Component
public class FileApiFallbackFactory implements FallbackFactory <IFileApi> {
    @Override
    public IFileApi create(Throwable throwable) {
        log.error ( "文件服务调用失败:{}", throwable.getMessage ( ) );
        throwable.printStackTrace ( );
        return new IFileApi ( ) {

            @Override
            public void download(String uploadPath, String name, HttpServletResponse response) throws Exception {

            }

            @Override
            public ResponseEntity upload(HttpServletRequest request, MultipartFile file) {
                return null;
            }
        };
    }
}
