From 6922792ad110ce9194aa963674bbf2c5c1351ea1 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 26 Aug 2023 17:45:26 -0400 Subject: [PATCH] Add more user-friendly network-related exception messages --- .../kanade/presentation/util/ExceptionFormatter.kt | 12 +++++++++++- i18n/src/main/res/values/strings.xml | 8 ++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/util/ExceptionFormatter.kt b/app/src/main/java/eu/kanade/presentation/util/ExceptionFormatter.kt index 7169c9e9bd..9b4d4286f3 100644 --- a/app/src/main/java/eu/kanade/presentation/util/ExceptionFormatter.kt +++ b/app/src/main/java/eu/kanade/presentation/util/ExceptionFormatter.kt @@ -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) { diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index d6d6151fb0..bf7c33bb26 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -606,8 +606,6 @@ No more results No results found - - Check website in WebView Licensed - No chapters to show Local source Other @@ -947,4 +945,10 @@ See your recently updated library entries Widget not available when app lock is enabled You are about to remove \"%s\" from your library + + + + HTTP %d, check website in WebView + No Internet connection + Couldn\'t reach %s