Handle NoDataReceivedException

This commit is contained in:
Koitharu
2024-03-30 08:21:40 +02:00
parent bec032c7dc
commit 41f64b2e36
4 changed files with 16 additions and 2 deletions

View File

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

View File

@@ -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<Class<*>>(
IllegalArgumentException::class.java,
ConcurrentModificationException::class.java,
UnsupportedOperationException::class.java,
NoDataReceivedException::class.java,
)
fun Throwable.isWebViewUnavailable(): Boolean {

View File

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

View File

@@ -640,4 +640,5 @@
<string name="unsupported_source">This manga source is not supported</string>
<string name="show_pages_thumbs">Show pages thumbnails</string>
<string name="show_pages_thumbs_summary">Enable the \"Pages\" tab on the details screen</string>
<string name="error_no_data_received">No data was received from server</string>
</resources>