Skip to content

Commit 030e819

Browse files
committed
Merge pull request #700 from mderka/retries
Added retryable errors.
2 parents 44b1998 + 4f28101 commit 030e819

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsException.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,42 @@
1616

1717
package com.google.gcloud.dns;
1818

19+
import com.google.common.collect.ImmutableSet;
1920
import com.google.gcloud.BaseServiceException;
2021
import com.google.gcloud.RetryHelper.RetryHelperException;
2122
import com.google.gcloud.RetryHelper.RetryInterruptedException;
2223

2324
import java.io.IOException;
25+
import java.util.Set;
2426

2527
/**
2628
* DNS service exception.
2729
*/
2830
public class DnsException extends BaseServiceException {
2931

32+
// see: https://cloud.google.com/dns/troubleshooting
33+
private static final Set<Error> RETRYABLE_ERRORS = ImmutableSet.of(
34+
new Error(429, null),
35+
new Error(500, null),
36+
new Error(502, null),
37+
new Error(503, null),
38+
new Error(null, "userRateLimitExceeded"),
39+
new Error(null, "rateLimitExceeded"));
3040
private static final long serialVersionUID = 490302380416260252L;
3141

3242
public DnsException(IOException exception) {
3343
super(exception, true);
3444
}
3545

36-
public DnsException(int code, String message) {
46+
private DnsException(int code, String message) {
3747
super(code, message, null, true);
3848
}
3949

50+
@Override
51+
protected Set<Error> retryableErrors() {
52+
return RETRYABLE_ERRORS;
53+
}
54+
4055
/**
4156
* Translate RetryHelperException to the DnsException that caused the error. This method will
4257
* always throw an exception.
@@ -48,6 +63,4 @@ static DnsException translateAndThrow(RetryHelperException ex) {
4863
BaseServiceException.translateAndPropagateIfPossible(ex);
4964
throw new DnsException(UNKNOWN_CODE, ex.getMessage());
5065
}
51-
52-
//TODO(mderka) Add translation and retry functionality. Created issue #593.
5366
}

0 commit comments

Comments
 (0)