@@ -58,6 +58,16 @@ public String reason() {
58
58
return reason ;
59
59
}
60
60
61
+ boolean isRetryable (Set <Error > retryableErrors ) {
62
+ for (Error retryableError : retryableErrors ) {
63
+ if ((retryableError .code () == null || retryableError .code ().equals (this .code ()))
64
+ && (retryableError .reason () == null || retryableError .reason ().equals (this .reason ()))) {
65
+ return true ;
66
+ }
67
+ }
68
+ return false ;
69
+ }
70
+
61
71
@ Override
62
72
public String toString () {
63
73
return MoreObjects .toStringHelper (this ).add ("code" , code ).add ("reason" , reason ).toString ();
@@ -83,7 +93,7 @@ public BaseServiceException(IOException exception, boolean idempotent) {
83
93
Error error = error (((GoogleJsonResponseException ) exception ).getDetails ());
84
94
this .code = error .code ;
85
95
this .reason = error .reason ;
86
- this .retryable = isRetryable (error );
96
+ this .retryable = error . isRetryable (retryableErrors () );
87
97
} else {
88
98
this .code = UNKNOWN_CODE ;
89
99
this .reason = null ;
@@ -110,15 +120,15 @@ public BaseServiceException(int code, String message, String reason, boolean ide
110
120
this .code = code ;
111
121
this .reason = reason ;
112
122
this .idempotent = idempotent ;
113
- this .retryable = idempotent && isRetryable ( new Error (code , reason ));
123
+ this .retryable = idempotent && new Error (code , reason ). isRetryable ( retryableErrors ( ));
114
124
}
115
125
116
126
protected Set <Error > retryableErrors () {
117
127
return Collections .emptySet ();
118
128
}
119
129
120
130
protected boolean isRetryable (GoogleJsonError error ) {
121
- return error != null && isRetryable ( error (error ));
131
+ return error != null && error (error ). isRetryable ( retryableErrors ( ));
122
132
}
123
133
124
134
protected boolean isRetryable (IOException exception ) {
@@ -128,16 +138,6 @@ protected boolean isRetryable(IOException exception) {
128
138
return exception instanceof SocketTimeoutException ;
129
139
}
130
140
131
- protected boolean isRetryable (Error error ) {
132
- for (Error retryableError : retryableErrors ()) {
133
- if ((retryableError .code () == null || retryableError .code ().equals (error .code ()))
134
- && (retryableError .reason () == null || retryableError .reason ().equals (error .reason ()))) {
135
- return true ;
136
- }
137
- }
138
- return false ;
139
- }
140
-
141
141
/**
142
142
* Returns the code associated with this exception.
143
143
*/
0 commit comments