Skip to content

Commit

Permalink
Merge pull request #700 from mderka/retries
Browse files Browse the repository at this point in the history
Added retryable errors.
  • Loading branch information
mderka committed Mar 3, 2016
2 parents 44b1998 + 4f28101 commit 030e819
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,42 @@

package com.google.gcloud.dns;

import com.google.common.collect.ImmutableSet;
import com.google.gcloud.BaseServiceException;
import com.google.gcloud.RetryHelper.RetryHelperException;
import com.google.gcloud.RetryHelper.RetryInterruptedException;

import java.io.IOException;
import java.util.Set;

/**
* DNS service exception.
*/
public class DnsException extends BaseServiceException {

// see: https://cloud.google.com/dns/troubleshooting
private static final Set<Error> RETRYABLE_ERRORS = ImmutableSet.of(
new Error(429, null),
new Error(500, null),
new Error(502, null),
new Error(503, null),
new Error(null, "userRateLimitExceeded"),
new Error(null, "rateLimitExceeded"));
private static final long serialVersionUID = 490302380416260252L;

public DnsException(IOException exception) {
super(exception, true);
}

public DnsException(int code, String message) {
private DnsException(int code, String message) {
super(code, message, null, true);
}

@Override
protected Set<Error> retryableErrors() {
return RETRYABLE_ERRORS;
}

/**
* Translate RetryHelperException to the DnsException that caused the error. This method will
* always throw an exception.
Expand All @@ -48,6 +63,4 @@ static DnsException translateAndThrow(RetryHelperException ex) {
BaseServiceException.translateAndPropagateIfPossible(ex);
throw new DnsException(UNKNOWN_CODE, ex.getMessage());
}

//TODO(mderka) Add translation and retry functionality. Created issue #593.
}

0 comments on commit 030e819

Please sign in to comment.