From 589bdba0b1538266b7786591046f88a1159cbb8c Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Wed, 1 Feb 2023 11:36:53 +0800 Subject: [PATCH] Show exception class in snackbar message (#9006) * Show exception class in snackbar message * omit IOException too --- .../eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 0748037ee..dcac94e1b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -225,8 +225,7 @@ class MangaInfoScreenModel( logcat(LogPriority.ERROR, e) coroutineScope.launch { - val errorMessage = e.message.orEmpty().ifEmpty { e.toString() } - snackbarHostState.showSnackbar(message = errorMessage) + snackbarHostState.showSnackbar(message = e.snackbarMessage) } } } @@ -516,7 +515,7 @@ class MangaInfoScreenModel( context.getString(R.string.no_chapters_error) } else { logcat(LogPriority.ERROR, e) - e.message.orEmpty().ifEmpty { e.toString() } + e.snackbarMessage } coroutineScope.launch { @@ -1056,3 +1055,10 @@ val chapterDecimalFormat = DecimalFormat( DecimalFormatSymbols() .apply { decimalSeparator = '.' }, ) + +private val Throwable.snackbarMessage: String + get() = when (val className = this::class.simpleName) { + null -> message ?: "" + "Exception", "HttpException", "IOException" -> message ?: className + else -> "$className: $message" + }