Add more user-friendly network-related exception messages

This commit is contained in:
arkon
2023-08-26 17:45:26 -04:00
parent f32243899d
commit 6922792ad1
2 changed files with 17 additions and 3 deletions

View File

@@ -4,16 +4,26 @@ import android.content.Context
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.network.HttpException
import eu.kanade.tachiyomi.source.online.LicensedMangaChaptersException
import eu.kanade.tachiyomi.util.system.isOnline
import tachiyomi.data.source.NoResultsException
import tachiyomi.domain.source.model.SourceNotInstalledException
import java.net.UnknownHostException
context(Context)
val Throwable.formattedMessage: String
get() {
when (this) {
is HttpException -> return getString(R.string.exception_http, code)
is UnknownHostException -> {
return if (!isOnline()) {
getString(R.string.exception_offline)
} else {
getString(R.string.exception_unknown_host, message)
}
}
is NoResultsException -> return getString(R.string.no_results_found)
is SourceNotInstalledException -> return getString(R.string.loader_not_implemented_error)
is HttpException -> return "$message: ${getString(R.string.http_error_hint)}"
is LicensedMangaChaptersException -> return getString(R.string.licensed_manga_chapters_error)
}
return when (val className = this::class.simpleName) {