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.R
import eu.kanade.tachiyomi.network.HttpException import eu.kanade.tachiyomi.network.HttpException
import eu.kanade.tachiyomi.source.online.LicensedMangaChaptersException import eu.kanade.tachiyomi.source.online.LicensedMangaChaptersException
import eu.kanade.tachiyomi.util.system.isOnline
import tachiyomi.data.source.NoResultsException import tachiyomi.data.source.NoResultsException
import tachiyomi.domain.source.model.SourceNotInstalledException import tachiyomi.domain.source.model.SourceNotInstalledException
import java.net.UnknownHostException
context(Context) context(Context)
val Throwable.formattedMessage: String val Throwable.formattedMessage: String
get() { get() {
when (this) { 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 NoResultsException -> return getString(R.string.no_results_found)
is SourceNotInstalledException -> return getString(R.string.loader_not_implemented_error) 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) is LicensedMangaChaptersException -> return getString(R.string.licensed_manga_chapters_error)
} }
return when (val className = this::class.simpleName) { return when (val className = this::class.simpleName) {

View File

@ -606,8 +606,6 @@
<!-- missing prompt after Compose rewrite #7901 --> <!-- missing prompt after Compose rewrite #7901 -->
<string name="no_more_results">No more results</string> <string name="no_more_results">No more results</string>
<string name="no_results_found">No results found</string> <string name="no_results_found">No results found</string>
<!-- Do not translate "WebView" -->
<string name="http_error_hint">Check website in WebView</string>
<string name="licensed_manga_chapters_error">Licensed - No chapters to show</string> <string name="licensed_manga_chapters_error">Licensed - No chapters to show</string>
<string name="local_source">Local source</string> <string name="local_source">Local source</string>
<string name="other_source">Other</string> <string name="other_source">Other</string>
@ -947,4 +945,10 @@
<string name="appwidget_updates_description">See your recently updated library entries</string> <string name="appwidget_updates_description">See your recently updated library entries</string>
<string name="appwidget_unavailable_locked">Widget not available when app lock is enabled</string> <string name="appwidget_unavailable_locked">Widget not available when app lock is enabled</string>
<string name="remove_manga">You are about to remove \"%s\" from your library</string> <string name="remove_manga">You are about to remove \"%s\" from your library</string>
<!-- Common exceptions -->
<!-- Do not translate "WebView" -->
<string name="exception_http">HTTP %d, check website in WebView</string>
<string name="exception_offline">No Internet connection</string>
<string name="exception_unknown_host">Couldn\'t reach %s</string>
</resources> </resources>