16
16
17
17
package com .google .gcloud .dns ;
18
18
19
+ import com .google .common .collect .ImmutableSet ;
19
20
import com .google .gcloud .BaseServiceException ;
20
21
import com .google .gcloud .RetryHelper .RetryHelperException ;
21
22
import com .google .gcloud .RetryHelper .RetryInterruptedException ;
22
23
23
24
import java .io .IOException ;
25
+ import java .util .Set ;
24
26
25
27
/**
26
28
* DNS service exception.
27
29
*/
28
30
public class DnsException extends BaseServiceException {
29
31
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" ));
30
40
private static final long serialVersionUID = 490302380416260252L ;
31
41
32
42
public DnsException (IOException exception ) {
33
43
super (exception , true );
34
44
}
35
45
36
- public DnsException (int code , String message ) {
46
+ private DnsException (int code , String message ) {
37
47
super (code , message , null , true );
38
48
}
39
49
50
+ @ Override
51
+ protected Set <Error > retryableErrors () {
52
+ return RETRYABLE_ERRORS ;
53
+ }
54
+
40
55
/**
41
56
* Translate RetryHelperException to the DnsException that caused the error. This method will
42
57
* always throw an exception.
@@ -48,6 +63,4 @@ static DnsException translateAndThrow(RetryHelperException ex) {
48
63
BaseServiceException .translateAndPropagateIfPossible (ex );
49
64
throw new DnsException (UNKNOWN_CODE , ex .getMessage ());
50
65
}
51
-
52
- //TODO(mderka) Add translation and retry functionality. Created issue #593.
53
66
}
0 commit comments