diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/NoDataReceivedException.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/NoDataReceivedException.kt new file mode 100644 index 000000000..f8de32a1e --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/NoDataReceivedException.kt @@ -0,0 +1,7 @@ +package org.koitharu.kotatsu.core.exceptions + +import okio.IOException + +class NoDataReceivedException( + private val url: String, +) : IOException("No data has been received from $url") diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt index c133b2e42..c19d76c6c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt @@ -8,12 +8,12 @@ import coil.network.HttpException import okio.FileNotFoundException import okio.IOException import org.acra.ktx.sendWithAcra -import org.json.JSONException import org.jsoup.HttpStatusException import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.exceptions.CaughtException import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException +import org.koitharu.kotatsu.core.exceptions.NoDataReceivedException import org.koitharu.kotatsu.core.exceptions.SyncApiException import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions import org.koitharu.kotatsu.core.exceptions.UnsupportedFileException @@ -55,6 +55,8 @@ fun Throwable.getDisplayMessage(resources: Resources): String = when (this) { is SocketTimeoutException, -> resources.getString(R.string.network_error) + is NoDataReceivedException -> resources.getString(R.string.error_no_data_received) + is WrongPasswordException -> resources.getString(R.string.wrong_password) is NotFoundException -> resources.getString(R.string.not_found_404) is UnsupportedSourceException -> resources.getString(R.string.unsupported_source) @@ -115,6 +117,7 @@ private val reportableExceptions = arraySetOf>( IllegalArgumentException::class.java, ConcurrentModificationException::class.java, UnsupportedOperationException::class.java, + NoDataReceivedException::class.java, ) fun Throwable.isWebViewUnavailable(): Boolean { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/PagesCache.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/PagesCache.kt index 4f81808b1..a8c3763f7 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/PagesCache.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/PagesCache.kt @@ -12,6 +12,7 @@ import okio.Source import okio.buffer import okio.sink import okio.use +import org.koitharu.kotatsu.core.exceptions.NoDataReceivedException import org.koitharu.kotatsu.core.util.FileSize import org.koitharu.kotatsu.core.util.ext.compressToPNG import org.koitharu.kotatsu.core.util.ext.longHashCode @@ -62,7 +63,9 @@ class PagesCache @Inject constructor(@ApplicationContext context: Context) { val bytes = file.sink(append = false).buffer().use { it.writeAllCancellable(source) } - check(bytes != 0L) { "No data has been written" } + if (bytes == 0L) { + throw NoDataReceivedException(url) + } lruCache.get().put(url, file) } finally { file.delete() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dc43f6d41..6970d4c88 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -640,4 +640,5 @@ This manga source is not supported Show pages thumbnails Enable the \"Pages\" tab on the details screen + No data was received from server