Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private void notifyResponsePublisherErrorIfNeeded(Throwable error) {
private void handleServiceError(int responseStatus, HttpHeader[] headers, byte[] errorPayload) {
SdkHttpResponse.Builder errorResponse = populateSdkHttpResponse(SdkHttpResponse.builder(),
responseStatus, headers);
if (requestFailedMidwayOfOtherError(responseStatus)) {
if (requestFailedMidwayOfOtherError(responseStatus) || isSuccessStatus(responseStatus)) {
AwsServiceException s3Exception = buildS3Exception(responseStatus, errorPayload, errorResponse);

SdkClientException sdkClientException =
Expand All @@ -226,6 +226,10 @@ private void handleServiceError(int responseStatus, HttpHeader[] headers, byte[]
}
}

private static boolean isSuccessStatus(int responseStatus) {
return responseStatus >= 200 && responseStatus < 300;
}

private static AwsServiceException buildS3Exception(int responseStatus,
byte[] errorPayload,
SdkHttpResponse.Builder errorResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ public void errorResponse_shouldCompleteFutureSuccessfully() {
verify(sdkResponseHandler).onHeaders(any(SdkHttpResponse.class));
}

@Test
public void errorResponseWith200Status_shouldCompleteFutureExceptionally() {
int statusCode = 200;
responseHandlerAdapter.onResponseHeaders(statusCode, new HttpHeader[0]);

byte[] errorPayload = "errorResponse".getBytes(StandardCharsets.UTF_8);
responseHandlerAdapter.onFinished(stubResponseContext(1, statusCode, errorPayload));

Throwable actualException = sdkResponseHandler.error;
assertThat(actualException).isInstanceOf(S3Exception.class);
assertThat(((S3Exception) actualException).statusCode()).isEqualTo(200);
assertThat(future).isCompletedExceptionally();
verify(s3MetaRequest).close();
}

@Test
public void requestFailed_shouldCompleteFutureExceptionally() {

Expand Down