From 058ee4c86b15a7d4a11b9e4fb934e69a7c2ac19c Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Fri, 28 Apr 2023 21:06:32 +0800 Subject: [PATCH] Fix exception formatter's format (#9413) --- .../presentation/util/ExceptionFormatter.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 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 ff7ae44ae..a69bcfcbe 100644 --- a/app/src/main/java/eu/kanade/presentation/util/ExceptionFormatter.kt +++ b/app/src/main/java/eu/kanade/presentation/util/ExceptionFormatter.kt @@ -5,15 +5,17 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.network.HttpException import tachiyomi.data.source.NoResultsException import tachiyomi.domain.source.model.SourceNotInstalledException -import java.io.IOException context(Context) val Throwable.formattedMessage: String - get() = when { - this is NoResultsException -> getString(R.string.no_results_found) - this is SourceNotInstalledException -> getString(R.string.loader_not_implemented_error) - this is HttpException -> "$message: ${getString(R.string.http_error_hint)}" - this is IOException || this is Exception -> message ?: this::class.simpleName.orEmpty() - this::class.simpleName != null -> "${this::class.simpleName}: $message" - else -> message.orEmpty() + get() { + when (this) { + 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)}" + } + return when (val className = this::class.simpleName) { + "Exception", "IOException" -> message ?: className + else -> "$className: $message" + } }