package com.inspect.system.base.factory;

import com.inspect.base.core.domain.Response;
import com.inspect.system.base.RemoteFileService;
import com.inspect.system.base.domain.SysFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {
   private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);

   public RemoteFileService create(final Throwable throwable) {
      log.error("文件服务调用失败:{}", throwable.getMessage());
      return new RemoteFileService() {
         public Response<SysFile> upload(MultipartFile file) {
            return Response.fail("上传文件失败:" + throwable.getMessage());
         }
      };
   }
}
