项目作者: dubilyer

项目描述 :
A library with useful nice to have extensions for okhttp/retrofit client.
高级语言: Java
项目地址: git://github.com/dubilyer/Retrofit-Sugar.git
创建时间: 2020-10-08T13:03:47Z
项目社区:https://github.com/dubilyer/Retrofit-Sugar

开源协议:

下载


Retrofit-Sugar

The purpose of this project is to add some useful features for okhttp/retrofit rest cient.

RetryInterceptor

it’s a universal interceptor for retrying API calls.

Usage

  1. RetryInterceptorBuilder retryInterceptorBuilder = RetryInterceptor
  2. .retry()
  3. .untilTimes(3)
  4. .each(100, MILLISECONDS)
  5. .withListener(retryCountListener)
  6. .ifConditionOccurs(Code.equalsTo(200)).negate()
  7. .ifExceptionThrown(ArithmeticException.class)
  8. .build();
  9.  
  10. OkHttpClient client = new OkHttpClient.Builder().addInterceptor().build();

In this particular case any API request made by client will be retryed up to 3 times each 100 ms while response code is not 200 and no exception is thrown.