@@ -58,6 +58,16 @@ public String reason() {
5858 return reason ;
5959 }
6060
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+
6171 @ Override
6272 public String toString () {
6373 return MoreObjects .toStringHelper (this ).add ("code" , code ).add ("reason" , reason ).toString ();
@@ -83,7 +93,7 @@ public BaseServiceException(IOException exception, boolean idempotent) {
8393 Error error = error (((GoogleJsonResponseException ) exception ).getDetails ());
8494 this .code = error .code ;
8595 this .reason = error .reason ;
86- this .retryable = isRetryable (error );
96+ this .retryable = error . isRetryable (retryableErrors () );
8797 } else {
8898 this .code = UNKNOWN_CODE ;
8999 this .reason = null ;
@@ -110,15 +120,15 @@ public BaseServiceException(int code, String message, String reason, boolean ide
110120 this .code = code ;
111121 this .reason = reason ;
112122 this .idempotent = idempotent ;
113- this .retryable = idempotent && isRetryable ( new Error (code , reason ));
123+ this .retryable = idempotent && new Error (code , reason ). isRetryable ( retryableErrors ( ));
114124 }
115125
116126 protected Set <Error > retryableErrors () {
117127 return Collections .emptySet ();
118128 }
119129
120130 protected boolean isRetryable (GoogleJsonError error ) {
121- return error != null && isRetryable ( error (error ));
131+ return error != null && error (error ). isRetryable ( retryableErrors ( ));
122132 }
123133
124134 protected boolean isRetryable (IOException exception ) {
@@ -128,16 +138,6 @@ protected boolean isRetryable(IOException exception) {
128138 return exception instanceof SocketTimeoutException ;
129139 }
130140
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-
141141 /**
142142 * Returns the code associated with this exception.
143143 */
0 commit comments