1616
1717package com .google .gcloud .dns ;
1818
19+ import com .google .common .collect .ImmutableSet ;
1920import com .google .gcloud .BaseServiceException ;
2021import com .google .gcloud .RetryHelper .RetryHelperException ;
2122import com .google .gcloud .RetryHelper .RetryInterruptedException ;
2223
2324import java .io .IOException ;
25+ import java .util .Set ;
2426
2527/**
2628 * DNS service exception.
2729 */
2830public 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