From 0d41990cb94a3f265a4637b34ed93fe18d88f4f5 Mon Sep 17 00:00:00 2001 From: Tinashe Mzondiwa Date: Sun, 6 Mar 2022 11:37:29 +0200 Subject: [PATCH] Increase write timeout --- .../src/main/kotlin/BuildAndroidConfig.kt | 2 +- .../java/app/ss/lessons/data/di/ApiModule.kt | 1 + .../lessons/ReaderArtifactHelper.kt | 22 +++++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/buildSrc/src/main/kotlin/BuildAndroidConfig.kt b/buildSrc/src/main/kotlin/BuildAndroidConfig.kt index b80e8e370..e2aee848c 100644 --- a/buildSrc/src/main/kotlin/BuildAndroidConfig.kt +++ b/buildSrc/src/main/kotlin/BuildAndroidConfig.kt @@ -12,7 +12,7 @@ object BuildAndroidConfig { object Version { private const val MAJOR = 4 private const val MINOR = 9 - private const val PATCH = 0 + private const val PATCH = 1 const val name = "$MAJOR.$MINOR.$PATCH" } diff --git a/common/lessons-data/src/main/java/app/ss/lessons/data/di/ApiModule.kt b/common/lessons-data/src/main/java/app/ss/lessons/data/di/ApiModule.kt index 63082e428..fbb7a791f 100644 --- a/common/lessons-data/src/main/java/app/ss/lessons/data/di/ApiModule.kt +++ b/common/lessons-data/src/main/java/app/ss/lessons/data/di/ApiModule.kt @@ -64,6 +64,7 @@ object ApiModule { ): OkHttpClient = OkHttpClient.Builder() .connectTimeout(1, TimeUnit.MINUTES) .readTimeout(1, TimeUnit.MINUTES) + .writeTimeout(2, TimeUnit.MINUTES) .addInterceptor( HttpLoggingInterceptor().apply { level = if (BuildConfig.DEBUG) diff --git a/common/lessons-data/src/main/java/app/ss/lessons/data/repository/lessons/ReaderArtifactHelper.kt b/common/lessons-data/src/main/java/app/ss/lessons/data/repository/lessons/ReaderArtifactHelper.kt index 31c05a7a9..f2a4a7e4e 100644 --- a/common/lessons-data/src/main/java/app/ss/lessons/data/repository/lessons/ReaderArtifactHelper.kt +++ b/common/lessons-data/src/main/java/app/ss/lessons/data/repository/lessons/ReaderArtifactHelper.kt @@ -47,6 +47,7 @@ internal class ReaderArtifactHelper @Inject constructor( @ApplicationContext private val context: Context, private val lessonsApi: SSLessonsApi, private val ssPrefs: SSPrefs, + private val okHttpClient: OkHttpClient, private val dispatcherProvider: DispatcherProvider, private val connectivityHelper: ConnectivityHelper ) : CoroutineScope by CoroutineScope(dispatcherProvider.default) { @@ -78,16 +79,19 @@ internal class ReaderArtifactHelper @Inject constructor( val request = Request.Builder() .url(URL) .build() - OkHttpClient() - .newCall(request) - .execute() - .use { response -> - val body = response.body ?: return@use - destination.sink().buffer().use { sink -> - sink.writeAll(body.source()) - callback() - } + try { + val response = okHttpClient.newCall(request).execute() + val body = response.body ?: run { + Timber.e("Failed to download reader") + return + } + destination.sink().buffer().use { sink -> + sink.writeAll(body.source()) + callback() } + } catch (error: Throwable) { + Timber.e(error) + } } companion object {