Show exception class in snackbar message (#9006)

* Show exception class in snackbar message

* omit IOException too
This commit is contained in:
stevenyomi 2023-02-01 11:36:53 +08:00 committed by GitHub
parent aca65f13bb
commit 589bdba0b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -225,8 +225,7 @@ class MangaInfoScreenModel(
logcat(LogPriority.ERROR, e) logcat(LogPriority.ERROR, e)
coroutineScope.launch { coroutineScope.launch {
val errorMessage = e.message.orEmpty().ifEmpty { e.toString() } snackbarHostState.showSnackbar(message = e.snackbarMessage)
snackbarHostState.showSnackbar(message = errorMessage)
} }
} }
} }
@ -516,7 +515,7 @@ class MangaInfoScreenModel(
context.getString(R.string.no_chapters_error) context.getString(R.string.no_chapters_error)
} else { } else {
logcat(LogPriority.ERROR, e) logcat(LogPriority.ERROR, e)
e.message.orEmpty().ifEmpty { e.toString() } e.snackbarMessage
} }
coroutineScope.launch { coroutineScope.launch {
@ -1056,3 +1055,10 @@ val chapterDecimalFormat = DecimalFormat(
DecimalFormatSymbols() DecimalFormatSymbols()
.apply { decimalSeparator = '.' }, .apply { decimalSeparator = '.' },
) )
private val Throwable.snackbarMessage: String
get() = when (val className = this::class.simpleName) {
null -> message ?: ""
"Exception", "HttpException", "IOException" -> message ?: className
else -> "$className: $message"
}