so I need show specific screen when there is a request timeout. I am using this code to init the retrofit
object RetrofitServiceGenerator {
private val loggingInterceptor = HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
private val okHttpClient = OkHttpClient.Builder()
.callTimeout(7, TimeUnit.SECONDS)
.addInterceptor(loggingInterceptor)
.build()
private var retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build()
fun <T> getInstance(APIType: Class<T>) : T {
return retrofit.create(APIType)
}
}
so after 7 seconds, I want to show a specific screen, but the problem is, I don't know, when I get notified if there is a request timeout in my code. for example in my code below
val call = restaurantService.getRestaurantDetail(restaurantID)
call.enqueue(object: Callback<Restaurant>{
override fun onFailure(call: Call<Restaurant>, t: Throwable) {
}
override fun onResponse(call: Call<Restaurant>, response: Response<Restaurant>) {
}
})
java or kotlin are ok