diff --git a/src/main/java/com/asaas/apisdk/http/interceptors/RetryInterceptor.java b/src/main/java/com/asaas/apisdk/http/interceptors/RetryInterceptor.java index 61c8896..b09e88d 100644 --- a/src/main/java/com/asaas/apisdk/http/interceptors/RetryInterceptor.java +++ b/src/main/java/com/asaas/apisdk/http/interceptors/RetryInterceptor.java @@ -28,16 +28,17 @@ public Response intercept(Chain chain) throws IOException { try { response = chain.proceed(request); - if (!isRetryable(response)) { + if (!isRetryable(response) || tryCount == config.getMaxRetries()) { return response; } - tryCount++; } catch (IOException e) { if (!config.getExceptionsToRetry().contains(e.getClass()) || tryCount == config.getMaxRetries()) { throw e; } } + tryCount++; + final int delay = calculateDelay(tryCount); try { Thread.sleep(delay); @@ -49,7 +50,6 @@ public Response intercept(Chain chain) throws IOException { return response; } - private int calculateDelay(int tryCount) { final int delay = (int) (config.getInitialDelay() * Math.pow(config.getBackoffFactor(), tryCount - 1)); return Math.min(delay, config.getMaxDelay());