Skip to content

Commit

Permalink
Show exception class in snackbar message (#9006)
Browse files Browse the repository at this point in the history
* Show exception class in snackbar message

* omit IOException too
  • Loading branch information
stevenyomi committed Feb 1, 2023
1 parent aca65f1 commit 589bdba
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
}

0 comments on commit 589bdba

Please sign in to comment.