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

fix: rely on google core for SSLException's #188

Merged
merged 4 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -35,7 +35,6 @@
public final class StorageException extends BaseHttpServiceException {
private static final String INTERNAL_ERROR = "internalError";
private static final String CONNECTION_CLOSED_PREMATURELY = "connectionClosedPrematurely";
private static final String CONNECTION_RESET = "connectionReset";

// see: https://cloud.google.com/storage/docs/resumable-uploads-xml#practices
private static final Set<Error> RETRYABLE_ERRORS =
Expand All @@ -47,8 +46,7 @@ public final class StorageException extends BaseHttpServiceException {
new Error(429, null),
new Error(408, null),
new Error(null, INTERNAL_ERROR),
new Error(null, CONNECTION_CLOSED_PREMATURELY),
new Error(null, CONNECTION_RESET));
new Error(null, CONNECTION_CLOSED_PREMATURELY));

private static final long serialVersionUID = -4168430271327813063L;

Expand Down Expand Up @@ -86,16 +84,14 @@ public static StorageException translateAndThrow(RetryHelperException ex) {
/**
* Translate IOException to a StorageException representing the cause of the error. This method
* defaults to idempotent always being {@code true}. Additionally, this method translates
* transient issues Connection Closed Prematurely and Connection Reset as retryable errors.
* transient issues Connection Closed Prematurely as a retryable error.
*
* @returns {@code StorageException}
*/
public static StorageException translate(IOException exception) {
if (exception.getMessage().contains("Connection closed prematurely")) {
return new StorageException(
0, exception.getMessage(), CONNECTION_CLOSED_PREMATURELY, exception);
} else if (exception.getMessage().contains("Connection reset")) {
return new StorageException(0, exception.getMessage(), CONNECTION_RESET, exception);
} else {
// default
return new StorageException(exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,23 @@ public void testStorageException() {
public void testTranslateConnectionReset() {
StorageException exception =
StorageException.translate(
new IOException(
new SSLException(
"Connection has been shutdown: "
+ new SSLException(new SocketException("Connection reset"))));
assertEquals(0, exception.getCode());
assertEquals("connectionReset", exception.getReason());
assertTrue(exception.isRetryable());
}

@Test
public void testTranslateConnectionShutdown() {
StorageException exception =
StorageException.translate(
new SSLException(
"Connection has been shutdown: "
+ new SSLException(new SocketException("Socket closed"))));
String test = exception.getMessage();

assertEquals(0, exception.getCode());
assertTrue(exception.isRetryable());
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<github.global.server>github</github.global.server>
<site.installationModule>google-cloud-storage-parent</site.installationModule>
<google.core.version>1.93.2</google.core.version>
<google.core.version>1.93.3</google.core.version>
<google.api-common.version>1.8.1</google.api-common.version>
<junit.version>4.13</junit.version>
<threeten.version>1.4.1</threeten.version>
Expand Down