There's no in built method to set the maximum limit, but you can add an interceptor like below.
client.interceptors().add(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
// try the request
Response response = chain.proceed(request);
int tryCount = 0;
int maxLimit = 3; //Set your max limit here
while (!response.isSuccessful() && tryCount < maxLimit) {
Log.d("intercept", "Request failed - " + tryCount);
tryCount++;
// retry the request
response = chain.proceed(request);
}
// otherwise just pass the original response on
return response;
}
});
More detail on interceptos can be found here.