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.
Prachi
  • 3,584
  • 2
  • 24
  • 39
  • Using the link you provided, would it possible to recreate a new HTTP client with the new timeout value? – Alexandre Marcq Jul 30 '21 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. – CommonsWare Jul 30 '21 at 13:19
  • This is a nice idea. However, is there any example or link for reference? – Prachi Jul 30 '21 at 13:25

0 Answers0