From aa580ac3b6c61bc7865293734c20a265fb0a111e Mon Sep 17 00:00:00 2001 From: theonefx Date: Wed, 7 Jul 2021 16:49:08 +0800 Subject: [PATCH] throw exception directly when exception is not an BlockException in SentinelProtectInterceptor --- .../custom/SentinelProtectInterceptor.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java index fbd468b26..63d688aed 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelProtectInterceptor.java @@ -86,13 +86,23 @@ public class SentinelProtectInterceptor implements ClientHttpRequestInterceptor Tracer.trace( new IllegalStateException("RestTemplate ErrorHandler has error")); } + return response; } catch (Throwable e) { - if (!BlockException.isBlockException(e)) { - Tracer.trace(e); + if (BlockException.isBlockException(e)) { + return handleBlockException(request, body, execution, (BlockException) e); } else { - return handleBlockException(request, body, execution, (BlockException) e); + Tracer.trace(e); + if (e instanceof IOException) { + throw (IOException) e; + } + else if (e instanceof RuntimeException) { + throw (RuntimeException) e; + } + else { + throw new IOException(e); + } } } finally { @@ -103,7 +113,6 @@ public class SentinelProtectInterceptor implements ClientHttpRequestInterceptor hostEntry.exit(); } } - return response; } private ClientHttpResponse handleBlockException(HttpRequest request, byte[] body,