diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DefaultDatastoreRpc.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DefaultDatastoreRpc.java index 4b39f7a3c4be..028027f4bc33 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DefaultDatastoreRpc.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DefaultDatastoreRpc.java @@ -42,6 +42,7 @@ import org.json.JSONTokener; import java.net.InetAddress; +import java.net.SocketTimeoutException; import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -121,9 +122,17 @@ private static DatastoreRpcException translate(DatastoreException exception) { if (reason == null) { reason = HTTP_STATUS_TO_REASON.get(exception.getCode()); } - return reason != null - ? new DatastoreRpcException(reason) - : new DatastoreRpcException("Unknown", exception.getCode(), false, message); + if (reason != null) { + return new DatastoreRpcException(reason); + } else { + boolean retryable = false; + reasonStr = "Unknown"; + if (exception.getCause() instanceof SocketTimeoutException) { + retryable = true; + reasonStr = "Request timeout"; + } + return new DatastoreRpcException(reasonStr, exception.getCode(), retryable, message); + } } @Override diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java index 1e2549550544..d874f99ebb4c 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java @@ -68,6 +68,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.SocketTimeoutException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -101,7 +102,11 @@ private static StorageException translate(IOException exception) { && ((GoogleJsonResponseException) exception).getDetails() != null) { translated = translate(((GoogleJsonResponseException) exception).getDetails()); } else { - translated = new StorageException(0, exception.getMessage(), false); + boolean retryable = false; + if (exception instanceof SocketTimeoutException) { + retryable = true; + } + translated = new StorageException(0, exception.getMessage(), retryable); } translated.initCause(exception); return translated;