@@ -104,7 +104,7 @@ class RetryInterceptor implements Interceptor {
104104 Stream .of (408 , 429 , 500 , 502 , 503 , 504 ).collect (Collectors .toSet ())
105105 );
106106 private static final int MAX_DELAY_MS = 10000 ;
107- private static final int MAX_BODY_SIZE = 1 * 1024 * 1024 ;
107+ private static final int MAX_BODY_SIZE = 1024 * 1024 ;
108108 private final int maxRetries ;
109109 private final long retryIntervalMs ;
110110 private final Set <Integer > businessRetryCodes ;
@@ -131,7 +131,7 @@ public Response intercept(Chain chain) throws IOException {
131131 try {
132132 response = chain .proceed (request );
133133 if (response .isSuccessful ()) {
134- if (enableBusinessRetry && shouldRetryForBusiness (response )) {
134+ if (shouldRetryForBusiness (response )) {
135135 waitForRetry (attempt );
136136 continue ;
137137 }
@@ -150,8 +150,12 @@ public Response intercept(Chain chain) throws IOException {
150150 }
151151 }
152152
153- if (exception != null ) throw exception ;
154- if (response != null ) return response ;
153+ if (exception != null ) {
154+ throw exception ;
155+ }
156+ if (response != null ) {
157+ return response ;
158+ }
155159 throw new IOException ("Failed after all retries with no response" );
156160 }
157161
@@ -177,8 +181,13 @@ private long calculateBackoff(int attempt) {
177181 }
178182
179183 private boolean shouldRetryForBusiness (Response response ) {
184+ if (!enableBusinessRetry ) {
185+ return false ;
186+ }
187+ if (businessRetryCodes == null || businessRetryCodes .isEmpty ()) {
188+ return false ;
189+ }
180190 try {
181- if (businessRetryCodes .isEmpty ()) return false ;
182191 ResponseBody peekBody = response .peekBody (MAX_BODY_SIZE );
183192 String responseBody = peekBody .source ().readByteString ().utf8 ();
184193 GenericResult result = JsonUtil .str2Obj (responseBody , resultType );
0 commit comments