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.

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

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.