diff --git a/app/src/main/java/org/koitharu/kotatsu/ui/reader/PageLoader.kt b/app/src/main/java/org/koitharu/kotatsu/ui/reader/PageLoader.kt index 663ab050e..b22312f54 100644 --- a/app/src/main/java/org/koitharu/kotatsu/ui/reader/PageLoader.kt +++ b/app/src/main/java/org/koitharu/kotatsu/ui/reader/PageLoader.kt @@ -30,7 +30,7 @@ class PageLoader : KoinComponent, CoroutineScope, DisposableHandle { return it } } - val task = tasks[url]?.takeUnless { it.isCancelled } + val task = tasks[url]?.takeUnless { it.isCancelled || (force && it.isCompleted) } return (task ?: loadAsync(url).also { tasks[url] = it }).await() } @@ -55,6 +55,9 @@ class PageLoader : KoinComponent, CoroutineScope, DisposableHandle { checkNotNull(body) { "Null response" } + check(response.isSuccessful) { + "Invalid response: ${response.code} ${response.message}" + } cache.put(url) { out -> body.byteStream().copyTo(out) } diff --git a/app/src/main/java/org/koitharu/kotatsu/utils/ext/CommonExt.kt b/app/src/main/java/org/koitharu/kotatsu/utils/ext/CommonExt.kt index 0c6e2b28d..9e8ae8a2a 100644 --- a/app/src/main/java/org/koitharu/kotatsu/utils/ext/CommonExt.kt +++ b/app/src/main/java/org/koitharu/kotatsu/utils/ext/CommonExt.kt @@ -7,7 +7,7 @@ import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException import org.koitharu.kotatsu.core.exceptions.UnsupportedFileException -import java.io.IOException +import java.net.SocketTimeoutException inline fun T.safe(action: T.() -> R?) = try { this.action() @@ -38,12 +38,8 @@ fun Throwable.getDisplayMessage(resources: Resources) = when (this) { is UnsupportedOperationException -> resources.getString(R.string.operation_not_supported) is UnsupportedFileException -> resources.getString(R.string.text_file_not_supported) is EmptyHistoryException -> resources.getString(R.string.history_is_empty) - is IOException -> resources.getString(R.string.network_error) - else -> if (BuildConfig.DEBUG) { - message ?: resources.getString(R.string.error_occurred) - } else { - resources.getString(R.string.error_occurred) - } + is SocketTimeoutException -> resources.getString(R.string.network_error) + else -> message ?: resources.getString(R.string.error_occurred) } inline fun measured(tag: String, block: () -> T): T {