With okhttp, I define okhttp connection timeout value to 3 secs to get timeout error.
OkHttpClient.Builder httpClient = new OkHttpClient().newBuilder()
.connectTimeout(3, TimeUnit.SECONDS)
.readTimeout(3, TimeUnit.SECONDS)
.writeTimeout(3, TimeUnit.SECONDS);
I used retrofit and rxjava to do network call and handle network error case with onError() consumer at subscribe method.
mTheApi.getMenuAPI(request)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
response -> {
Log.d(TAG, "getMenuAPI: " + response);
},
throwable -> {
// network error
Log.e(TAG, "getMenuAPI error: " + throwable.getMessage());
}
));
But when I call API with these timeout settings, connection never timeout for long API response time.
Normally It have to time out after 3 secs but still keep continue calling API more than 3 secs (more or less 10 secs).
How should I handle connection timeout for long response time?
Thanks in advance.