⏪ 回滚feign 自动降级的逻辑,方便调用方异常处理

This commit is contained in:
冷冷 committed 2024-05-11 12:38:11 +08:00
1 parent cc1a87944b
commit e50fb137e7
2 files changed
+6 -1

No files matched your search

@@ -46,7 +46,7 @@ public class PigxSentinelAutoConfiguration {
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "spring.cloud.openfeign.sentinel.enabled")
@ConditionalOnProperty(name = "spring.cloud.openfeign.sentinel.enabled",matchIfMissing = true)
public Feign.Builder feignSentinelBuilder() {
return PigxSentinelFeign.builder();
}
@@ -8,6 +8,7 @@ import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.Tracer;
import com.alibaba.csp.sentinel.context.ContextUtil;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.pig4cloud.pigx.common.core.util.R;
import feign.Feign;
import feign.InvocationHandlerFactory;
import feign.MethodMetadata;
@@ -118,6 +119,10 @@ public class PigxSentinelInvocationHandler implements InvocationHandler {
throw new AssertionError(e.getCause());
}
}
else if (R.class == method.getReturnType()) {
log.error("feign 服务间调用异常", ex);
return R.failed(ex.getLocalizedMessage());
}
else {
throw ex;
}