diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/BaseServiceException.java b/gcloud-java-core/src/main/java/com/google/gcloud/BaseServiceException.java index b91090f94e82..0222a0d2258c 100644 --- a/gcloud-java-core/src/main/java/com/google/gcloud/BaseServiceException.java +++ b/gcloud-java-core/src/main/java/com/google/gcloud/BaseServiceException.java @@ -58,6 +58,16 @@ public String reason() { return reason; } + boolean isRetryable(Set retryableErrors) { + for (Error retryableError : retryableErrors) { + if ((retryableError.code() == null || retryableError.code().equals(this.code())) + && (retryableError.reason() == null || retryableError.reason().equals(this.reason()))) { + return true; + } + } + return false; + } + @Override public String toString() { return MoreObjects.toStringHelper(this).add("code", code).add("reason", reason).toString(); @@ -83,7 +93,7 @@ public BaseServiceException(IOException exception, boolean idempotent) { Error error = error(((GoogleJsonResponseException) exception).getDetails()); this.code = error.code; this.reason = error.reason; - this.retryable = isRetryable(error); + this.retryable = error.isRetryable(retryableErrors()); } else { this.code = UNKNOWN_CODE; this.reason = null; @@ -110,7 +120,7 @@ public BaseServiceException(int code, String message, String reason, boolean ide this.code = code; this.reason = reason; this.idempotent = idempotent; - this.retryable = idempotent && isRetryable(new Error(code, reason)); + this.retryable = idempotent && new Error(code, reason).isRetryable(retryableErrors()); } protected Set retryableErrors() { @@ -118,7 +128,7 @@ protected Set retryableErrors() { } protected boolean isRetryable(GoogleJsonError error) { - return error != null && isRetryable(error(error)); + return error != null && error(error).isRetryable(retryableErrors()); } protected boolean isRetryable(IOException exception) { @@ -128,16 +138,6 @@ protected boolean isRetryable(IOException exception) { return exception instanceof SocketTimeoutException; } - protected boolean isRetryable(Error error) { - for (Error retryableError : retryableErrors()) { - if ((retryableError.code() == null || retryableError.code().equals(error.code())) - && (retryableError.reason() == null || retryableError.reason().equals(error.reason()))) { - return true; - } - } - return false; - } - /** * Returns the code associated with this exception. */