1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

calculate exception ratio in Sentinel RestTemplate

This commit is contained in:
fangjian0423 2018-12-18 22:20:52 +08:00
parent 89178bc913
commit ba101f479e

View File

@ -33,6 +33,7 @@ import org.springframework.util.ClassUtils;
import com.alibaba.csp.sentinel.Entry; import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.Tracer;
import com.alibaba.csp.sentinel.context.ContextUtil; import com.alibaba.csp.sentinel.context.ContextUtil;
import com.alibaba.csp.sentinel.slots.block.BlockException; import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException; import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
@ -69,16 +70,24 @@ public class SentinelProtectInterceptor implements ClientHttpRequestInterceptor
hostEntry = SphU.entry(hostResource); hostEntry = SphU.entry(hostResource);
response = execution.execute(request, body); response = execution.execute(request, body);
} }
catch (BlockException e) { catch (Throwable e) {
if (!BlockException.isBlockException(e)) {
Tracer.trace(e);
throw new IllegalStateException(e);
}
else {
try { try {
return handleBlockException(request, body, execution, e); return handleBlockException(request, body, execution,
(BlockException) e);
} }
catch (Exception ex) { catch (Exception ex) {
if (ex instanceof IllegalStateException) { if (ex instanceof IllegalStateException) {
throw (IllegalStateException) ex; throw (IllegalStateException) ex;
} }
throw new IllegalStateException( throw new IllegalStateException(
"sentinel handle BlockException error: " + ex.getMessage(), ex); "sentinel handle BlockException error: " + ex.getMessage(),
ex);
}
} }
} }
finally { finally {