Skip to content

Commit

Permalink
Move isRetryable method to BaseServiceException.Error
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Jan 20, 2016
1 parent 34e6806 commit 3c81f16
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public String reason() {
return reason;
}

boolean isRetryable(Set<Error> 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();
Expand All @@ -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;
Expand All @@ -110,15 +120,15 @@ 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<Error> retryableErrors() {
return Collections.emptySet();
}

protected boolean isRetryable(GoogleJsonError error) {
return error != null && isRetryable(error(error));
return error != null && error(error).isRetryable(retryableErrors());
}

protected boolean isRetryable(IOException exception) {
Expand All @@ -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.
*/
Expand Down

0 comments on commit 3c81f16

Please sign in to comment.