2

There is a situation where if my API call fails due timeout, I have to retry by increasing the timeout by 20 seconds. All the examples of retrofit I searched show static timeout. Something like in following How to set timeout in Retrofit library?

or ask to put timeout in @Headers field. But this is not suitable in my case. onFailure(), I want to

  1. increase the timeout by 20 seconds for retry attempt and then
  2. reset to original timeout.
3
  • Using the link you provided, would it possible to recreate a new HTTP client with the new timeout value? Commented Jul 30, 2021 at 13:14
  • 1
    Set the timeout in the OkHttpClient that you use to create your Retrofit instance. When you need to increase the timeout, use newBuilder() on the OkHttpClient and create a new OkHttpClient with all your old settings and the higher timeout. Then, create a new Retrofit instance from the new OkHttpClient, and use that for the higher-timeout call. When you are done with it, you can dispose of the new Retrofit and new OkHttpClient -- there will be nothing to "reset", because your original objects are untouched. Commented Jul 30, 2021 at 13:19
  • This is a nice idea. However, is there any example or link for reference? Commented Jul 30, 2021 at 13:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.