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 9b6929b
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,39 @@

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(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 +60,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 9b6929b

Please sign in to comment.