Fix page error processing

This commit is contained in:
Koitharu
2020-07-01 19:37:15 +03:00
parent c3ab197aa0
commit 367a97a95b
2 changed files with 7 additions and 8 deletions

View File

@@ -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)
}

View File

@@ -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, R> 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 <T> measured(tag: String, block: () -> T): T {