Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors should not be wrapped - Http #3431

Merged
merged 5 commits into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
davidh44 marked this conversation as resolved.
Show resolved Hide resolved
} 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);
}
}