Skip to content

Commit 821397a

Browse files
authored
Errors should not be wrapped - Http (#3431)
* Errors should not be wrapped - Http * Changelog entry * Cast Throwable to Exception * instance check of Exception * Refactor instance check
1 parent ba95988 commit 821397a

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"contributor": "",
4+
"type": "bugfix",
5+
"description": "Fixed issue where errors were being wrapped by SdkClientException"
6+
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/AsyncRetryableStage.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ private void attemptExecute(CompletableFuture<Response<OutputT>> future) {
156156
responseFuture.whenComplete((response, exception) -> {
157157

158158
if (exception != null) {
159-
maybeRetryExecute(future, exception);
159+
if (exception instanceof Exception) {
160+
maybeRetryExecute(future, (Exception) exception);
161+
} else {
162+
future.completeExceptionally(exception);
163+
}
160164
return;
161165
}
162166

@@ -175,7 +179,7 @@ private void attemptExecute(CompletableFuture<Response<OutputT>> future) {
175179
});
176180
}
177181

178-
private void maybeRetryExecute(CompletableFuture<Response<OutputT>> future, Throwable exception) {
182+
private void maybeRetryExecute(CompletableFuture<Response<OutputT>> future, Exception exception) {
179183
retryableStageHelper.setLastException(exception);
180184
retryableStageHelper.updateClientSendingRateForErrorResponse();
181185
maybeAttemptExecute(future);

core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/http/pipeline/stages/AsyncRetryableStageAdaptiveModeTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ public void execute_throttlingServiceException_updatesRate() throws Exception {
192192
verify(tokenBucket, never()).updateClientSendingRate(false);
193193
}
194194

195+
@Test
196+
public void execute_errorShouldNotBeWrapped() throws Exception {
197+
RetryPolicy retryPolicy = RetryPolicy.builder(RetryMode.ADAPTIVE)
198+
.numRetries(0)
199+
.build();
200+
201+
mockChildResponse(new OutOfMemoryError());
202+
retryableStage = createStage(retryPolicy);
203+
204+
SdkHttpFullRequest httpRequest = createHttpRequest();
205+
RequestExecutionContext executionContext = createExecutionContext();
206+
assertThatThrownBy(() -> retryableStage.execute(httpRequest, executionContext).join())
207+
.hasCauseInstanceOf(Error.class);
208+
}
209+
195210

196211
@Test
197212
public void execute_unsuccessfulResponse_nonThrottlingError_doesNotUpdateRate() throws Exception {
@@ -298,4 +313,9 @@ private void mockChildResponse(Exception error) throws Exception {
298313
CompletableFuture<Response<Object>> errorResult = CompletableFutureUtils.failedFuture(error);
299314
when(mockChildPipeline.execute(any(SdkHttpFullRequest.class), any(RequestExecutionContext.class))).thenReturn(errorResult);
300315
}
316+
317+
private void mockChildResponse(Error error) throws Exception {
318+
CompletableFuture<Response<Object>> errorResult = CompletableFutureUtils.failedFuture(error);
319+
when(mockChildPipeline.execute(any(SdkHttpFullRequest.class), any(RequestExecutionContext.class))).thenReturn(errorResult);
320+
}
301321
}

0 commit comments

Comments
 (0)