Skip to content

Commit

Permalink
Errors should not be wrapped - Http (#3431)
Browse files Browse the repository at this point in the history
* Errors should not be wrapped - Http

* Changelog entry

* Cast Throwable to Exception

* instance check of Exception

* Refactor instance check
  • Loading branch information
davidh44 committed Sep 21, 2022
1 parent ba95988 commit 821397a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-ee04822.json
@@ -0,0 +1,6 @@
{
"category": "AWS SDK for Java v2",
"contributor": "",
"type": "bugfix",
"description": "Fixed issue where errors were being wrapped by SdkClientException"
}
Expand Up @@ -156,7 +156,11 @@ private void attemptExecute(CompletableFuture<Response<OutputT>> future) {
responseFuture.whenComplete((response, exception) -> {

if (exception != null) {
maybeRetryExecute(future, exception);
if (exception instanceof Exception) {
maybeRetryExecute(future, (Exception) exception);
} else {
future.completeExceptionally(exception);
}
return;
}

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

private void maybeRetryExecute(CompletableFuture<Response<OutputT>> future, Throwable exception) {
private void maybeRetryExecute(CompletableFuture<Response<OutputT>> future, Exception exception) {
retryableStageHelper.setLastException(exception);
retryableStageHelper.updateClientSendingRateForErrorResponse();
maybeAttemptExecute(future);
Expand Down
Expand Up @@ -192,6 +192,21 @@ public void execute_throttlingServiceException_updatesRate() throws Exception {
verify(tokenBucket, never()).updateClientSendingRate(false);
}

@Test
public void execute_errorShouldNotBeWrapped() throws Exception {
RetryPolicy retryPolicy = RetryPolicy.builder(RetryMode.ADAPTIVE)
.numRetries(0)
.build();

mockChildResponse(new OutOfMemoryError());
retryableStage = createStage(retryPolicy);

SdkHttpFullRequest httpRequest = createHttpRequest();
RequestExecutionContext executionContext = createExecutionContext();
assertThatThrownBy(() -> retryableStage.execute(httpRequest, executionContext).join())
.hasCauseInstanceOf(Error.class);
}


@Test
public void execute_unsuccessfulResponse_nonThrottlingError_doesNotUpdateRate() throws Exception {
Expand Down Expand Up @@ -298,4 +313,9 @@ private void mockChildResponse(Exception error) throws Exception {
CompletableFuture<Response<Object>> errorResult = CompletableFutureUtils.failedFuture(error);
when(mockChildPipeline.execute(any(SdkHttpFullRequest.class), any(RequestExecutionContext.class))).thenReturn(errorResult);
}

private void mockChildResponse(Error error) throws Exception {
CompletableFuture<Response<Object>> errorResult = CompletableFutureUtils.failedFuture(error);
when(mockChildPipeline.execute(any(SdkHttpFullRequest.class), any(RequestExecutionContext.class))).thenReturn(errorResult);
}
}

0 comments on commit 821397a

Please sign in to comment.