Skip to content

Commit

Permalink
Added retryable errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka committed Mar 1, 2016
1 parent fa081ac commit e8620a3
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,41 @@

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(404, null),
new Error(409, null),
new Error(500, null),
new Error(502, null),
new Error(503, null));
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 +62,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 e8620a3

Please sign in to comment.