Skip to content
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.
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 @@ -33,18 +33,21 @@ public enum ExceptionHandler {

INVALID_OBJECT_STATE(
InvalidObjectStateException.class,
(cause, uri) -> createIOException("Object %s is in invalid state", uri, cause)),
(cause, uri) ->
createIOException("Object %s is in invalid state, failed with: %s", uri, cause)),

SDK_CLIENT(
SdkClientException.class,
(cause, uri) -> createIOException("Client error accessing %s", uri, cause)),
(cause, uri) -> createIOException("Client error accessing %s, failed with: %s", uri, cause)),

S3_SERVICE(
S3Exception.class,
(cause, uri) -> createIOException("Server error accessing %s", uri, cause)),
(cause, uri) ->
createIOException("Server error accessing %s, request failed with: %s", uri, cause)),

SDK_GENERAL(
SdkException.class, (cause, uri) -> createIOException("SDK error accessing %s", uri, cause));
SdkException.class,
(cause, uri) -> createIOException("SDK error accessing %s, failed with: %s", uri, cause));

private final Class<? extends Exception> exceptionClass;
private final ExceptionMapper mapper;
Expand Down Expand Up @@ -91,7 +94,7 @@ public static Exception[] getSampleExceptions() {
}

private static IOException createIOException(String message, S3URI uri, Throwable cause) {
return new IOException(String.format(message, uri), cause);
return new IOException(String.format(message, uri, cause.getMessage()), cause);
}

private static FileNotFoundException createFileNotFoundException(String message, S3URI uri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,31 @@ void testExceptionHandlerWithCompletionException() {
@Test
void testExceptionHandlerWithExecutionException() {
ExecutionException executionException =
new ExecutionException("Execution failed", InvalidObjectStateException.builder().build());
new ExecutionException(
"Execution failed",
InvalidObjectStateException.builder().message("InvalidObjectState").build());

Throwable result = ObjectClientUtil.handleException(S3_URI, executionException);

assertInstanceOf(IOException.class, result);
assertInstanceOf(InvalidObjectStateException.class, result.getCause());
assertEquals("Object s3://test-bucket/test-key is in invalid state", result.getMessage());
assertEquals(
"Object s3://test-bucket/test-key is in invalid state, failed with: InvalidObjectState",
result.getMessage());
}

@Test
void testExceptionHandlerWithSDKClientException() {
SdkClientException sdkClientException = SdkClientException.builder().build();
SdkClientException sdkClientException =
SdkClientException.builder().message("SdkClientException").build();

Throwable result = ObjectClientUtil.handleException(S3_URI, sdkClientException);

assertInstanceOf(IOException.class, result);
assertInstanceOf(SdkClientException.class, result.getCause());
assertEquals("Client error accessing s3://test-bucket/test-key", result.getMessage());
assertEquals(
"Client error accessing s3://test-bucket/test-key, failed with: SdkClientException",
result.getMessage());
}

@Test
Expand Down
Loading