Skip to content

Commit

Permalink
Minor cleanup refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka committed Apr 11, 2016
1 parent ae3e446 commit 2d198d0
Showing 1 changed file with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ public String reason() {

boolean isRetryable(boolean idempotent, Set<Error> retryableErrors) {
for (Error retryableError : retryableErrors) {
boolean match = (retryableError.code() == null || retryableError.code().equals(this.code()))
&& (retryableError.reason() == null || retryableError.reason().equals(this.reason()));
if (match && idempotent || match && retryableError.rejected()) {
return true;
if ((retryableError.code() == null || retryableError.code().equals(this.code()))
&& (retryableError.reason() == null || retryableError.reason().equals(this.reason()))) {
return idempotent || retryableError.rejected();
}
}
return false;
Expand Down Expand Up @@ -134,13 +133,7 @@ public BaseServiceException(IOException exception, boolean idempotent) {
}

public BaseServiceException(GoogleJsonError error, boolean idempotent) {
super(error.getMessage());
this.code = error.getCode();
this.reason = reason(error);
this.idempotent = idempotent;
this.retryable = isRetryable(idempotent, error);
this.location = null;
this.debugInfo = null;
this(error.getCode(), error.getMessage(), reason(error), idempotent);
}

public BaseServiceException(int code, String message, String reason, boolean idempotent) {
Expand All @@ -153,7 +146,7 @@ public BaseServiceException(int code, String message, String reason, boolean ide
this.code = code;
this.reason = reason;
this.idempotent = idempotent;
this.retryable = new Error(code, reason).isRetryable(idempotent, retryableErrors());
this.retryable = new Error(code, reason).isRetryable(idempotent, retryableErrors());
this.location = null;
this.debugInfo = null;
}
Expand All @@ -162,13 +155,15 @@ protected Set<Error> retryableErrors() {
return Collections.emptySet();
}

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

protected boolean isRetryable(boolean idempotent, IOException exception) {
if (exception instanceof GoogleJsonResponseException) {
return isRetryable(idempotent, (((GoogleJsonResponseException) exception).getDetails()));
GoogleJsonError googleJsonError = ((GoogleJsonResponseException) exception).getDetails();
return googleJsonError != null
&& error(googleJsonError).isRetryable(idempotent, retryableErrors());
}
return idempotent && exception instanceof SocketTimeoutException;
}
Expand Down

0 comments on commit 2d198d0

Please sign in to comment.