@@ -23,11 +23,6 @@ private SendTaskErrorConverter()
2323 {
2424 }
2525
26- private static final Map <Class <? extends Throwable >, BiFunction <? extends Throwable , String , ProcessError >> EXPECTED_CAUSES_WITH_CONVERTERS = Map
27- .of (SSLHandshakeException .class , convertSSLHandshakeException (), ConnectTimeoutException .class ,
28- convertConnectTimeoutException (), UnknownHostException .class , convertUnknownHostException (),
29- HttpHostConnectException .class , convertConnectTimeoutException ());
30-
3126 public static ProcessError convert (Exception exception , String action )
3227 {
3328 if (exception instanceof WebApplicationException e )
@@ -48,9 +43,31 @@ else if (exception instanceof HttpHostConnectException e)
4843 }
4944 else if (exception instanceof ProcessingException e )
5045 {
51- return EXPECTED_CAUSES_WITH_CONVERTERS .keySet ().stream ()
52- .map (causeClass -> getExpectedCauseInstanceFromStack (causeClass , e )).filter (Objects ::nonNull )
53- .findFirst ().map (ex -> applyConverter (ex , action )).orElse (applyConverter (e , action ));
46+ SSLHandshakeException sslHandshakeException = getExpectedCauseInstanceFromStack (SSLHandshakeException .class , e );
47+ if (sslHandshakeException != null )
48+ {
49+ return convertSSLHandshakeException ().apply (sslHandshakeException , action );
50+ }
51+
52+ ConnectTimeoutException connectTimeoutException = getExpectedCauseInstanceFromStack (ConnectTimeoutException .class , e );
53+ if (connectTimeoutException != null )
54+ {
55+ return convertConnectTimeoutException ().apply (connectTimeoutException , action );
56+ }
57+
58+ UnknownHostException unknownHostException = getExpectedCauseInstanceFromStack (UnknownHostException .class , e );
59+ if (unknownHostException != null )
60+ {
61+ return convertUnknownHostException ().apply (unknownHostException , action );
62+ }
63+
64+ HttpHostConnectException httpHostConnectException = getExpectedCauseInstanceFromStack (HttpHostConnectException .class , e );
65+ if (httpHostConnectException != null )
66+ {
67+ return convertHttpHostConnectException ().apply (httpHostConnectException , action );
68+ }
69+
70+ return convertExceptionFallback ().apply (e , action );
5471 }
5572 else
5673 {
@@ -100,15 +117,6 @@ private static BiFunction<UnknownHostException, String, ProcessError> convertUnk
100117 e .getMessage ());
101118 }
102119
103- private static <T extends Throwable > ProcessError applyConverter (T ex , String action )
104- {
105- @ SuppressWarnings ("unchecked" )
106- BiFunction <T , String , ProcessError > converter = (BiFunction <T , String , ProcessError >) EXPECTED_CAUSES_WITH_CONVERTERS
107- .getOrDefault (ex .getClass (), convertExceptionFallback ());
108- return converter .apply (ex , action );
109- }
110-
111-
112120 private static <T extends Throwable > T getExpectedCauseInstanceFromStack (Class <T > expectedCause , Throwable e )
113121 {
114122 if (Objects .isNull (e ))
0 commit comments