This commit is contained in:
xy
2024-06-20 16:05:26 +08:00
parent c994ada5e7
commit 6316389a68
7 changed files with 113 additions and 12 deletions

View File

@@ -0,0 +1,20 @@
package com.njcn.supervision.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.supervision.api.fallback.LineWarningFeignClientFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
/**
* 流程实例 Api 接口
* @author xy
*/
@FeignClient(value = ServerInfo.SUPERVISION, path = "/onlineMonitor", fallbackFactory = LineWarningFeignClientFallbackFactory.class)
public interface LineWarningFeignClient {
@PostMapping("/add")
HttpResult<String> add();
}

View File

@@ -0,0 +1,37 @@
package com.njcn.supervision.api.fallback;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.supervision.api.LineWarningFeignClient;
import com.njcn.supervision.utils.SupervisionEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author denghuajun
* @version 1.0.0
* @date 2022/3/16
*/
@Slf4j
@Component
public class LineWarningFeignClientFallbackFactory implements FallbackFactory<LineWarningFeignClient> {
@Override
public LineWarningFeignClient create(Throwable throwable) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (throwable.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) throwable.getCause();
exceptionEnum = SupervisionEnumUtil.getExceptionEnum(businessException.getResult());
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new LineWarningFeignClient() {
@Override
public HttpResult<String> add() {
log.error("{}异常,降级处理,异常为:{}", "新增终端检测数据", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}