0

I have a simple API request which I make by using Retrofit/OkHttp.

private fun getNext(
        nextId: Long
    ): Observable<NextData> =
        userRepo.getNext(nextId)
            .map { it.toDomainObject() }

The API replies 200, OK and it replies fast (definitely less than 3 seconds). However, this call sometimes throws

java.net.SocketTimeoutException: timeout

I also configured my OkHttpClient to have callTimeout(15, TimeUnit.SECONDS). I really do not understand why I have such an exception. Any ideas about solving this problem would be appreciated.

Tartar
  • 5,149
  • 16
  • 63
  • 104

1 Answers1

0

I don't code in Kotlin but maybe this will help you. I had same problem and this helped me in Java:

client = new OkHttpClient();
    client.setConnectTimeout(5, TimeUnit.MINUTES);
    client.setReadTimeout(5, TimeUnit.MINUTES);
    client.setWriteTimeout(5, TimeUnit.MINUTES);
Marina
  • 317
  • 4
  • 11