File tree Expand file tree Collapse file tree 2 files changed +37
-9
lines changed
kubernetes-client-api/src
main/java/io/fabric8/kubernetes/client/http
test/java/io/fabric8/kubernetes/client/http Expand file tree Collapse file tree 2 files changed +37
-9
lines changed Original file line number Diff line number Diff line change @@ -177,26 +177,31 @@ private <V> CompletableFuture<V> retryWithExponentialBackoff(
177
177
}
178
178
}
179
179
} else {
180
- final Throwable finalThrowable ;
181
- if (throwable instanceof CompletionException ) {
182
- finalThrowable = throwable .getCause ();
183
- } else {
184
- finalThrowable = throwable ;
185
- }
186
- builder .interceptors .forEach ((s , interceptor ) -> interceptor .afterConnectionFailure (request , finalThrowable ));
187
- if (finalThrowable instanceof IOException ) {
180
+ final Throwable actualCause = unwrapCompletionException (throwable );
181
+ builder .interceptors .forEach ((s , interceptor ) -> interceptor .afterConnectionFailure (request , actualCause ));
182
+ if (actualCause instanceof IOException ) {
188
183
// TODO: may not be specific enough - incorrect ssl settings for example will get caught here
189
184
LOG .debug (
190
185
String .format ("HTTP operation on url: %s should be retried after %d millis because of IOException" ,
191
186
uri , retryInterval ),
192
- finalThrowable );
187
+ actualCause );
193
188
return true ;
194
189
}
195
190
}
196
191
return false ;
197
192
});
198
193
}
199
194
195
+ static Throwable unwrapCompletionException (Throwable throwable ) {
196
+ final Throwable actualCause ;
197
+ if (throwable instanceof CompletionException ) {
198
+ actualCause = throwable .getCause ();
199
+ } else {
200
+ actualCause = throwable ;
201
+ }
202
+ return actualCause ;
203
+ }
204
+
200
205
static long retryAfterMillis (HttpResponse <?> httpResponse ) {
201
206
String retryAfter = httpResponse .header (StandardHttpHeaders .RETRY_AFTER );
202
207
if (retryAfter != null ) {
Original file line number Diff line number Diff line change 34
34
import java .util .Collections ;
35
35
import java .util .List ;
36
36
import java .util .concurrent .CompletableFuture ;
37
+ import java .util .concurrent .CompletionException ;
37
38
import java .util .concurrent .ExecutionException ;
38
39
import java .util .concurrent .TimeUnit ;
39
40
import java .util .concurrent .TimeoutException ;
50
51
51
52
class StandardHttpClientTest {
52
53
54
+ public static final String IO_ERROR_MESSAGE = "IO woopsie" ;
53
55
private TestStandardHttpClient client ;
54
56
55
57
@ BeforeEach
@@ -281,4 +283,25 @@ void testDerivedIsClosed() {
281
283
assertTrue (client .isClosed ());
282
284
}
283
285
286
+ @ Test
287
+ void shouldUnwrapCompletionException () {
288
+ // Given
289
+
290
+ // When
291
+ final Throwable throwable = StandardHttpClient .unwrapCompletionException (new CompletionException (new IOException (IO_ERROR_MESSAGE )));
292
+
293
+ // Then
294
+ assertThat (throwable ).isInstanceOf (IOException .class ).hasMessage (IO_ERROR_MESSAGE );
295
+ }
296
+
297
+ @ Test
298
+ void shouldNotUnwrapOtherExceptions () {
299
+ // Given
300
+
301
+ // When
302
+ final Throwable throwable = StandardHttpClient .unwrapCompletionException (new IOException (IO_ERROR_MESSAGE ));
303
+
304
+ // Then
305
+ assertThat (throwable ).isInstanceOf (IOException .class ).hasMessage (IO_ERROR_MESSAGE );
306
+ }
284
307
}
You can’t perform that action at this time.
0 commit comments