Mutualize :? part

This commit is contained in:
Benoit Marty 2019-08-05 18:30:31 +02:00
parent 357123743f
commit 7b5dff3dcf

View File

@ -31,15 +31,14 @@ class ErrorFormatter @Inject constructor(val stringProvider: StringProvider) {


fun toHumanReadable(throwable: Throwable?): String { fun toHumanReadable(throwable: Throwable?): String {
return when (throwable) { return when (throwable) {
null -> "" null -> null
is Failure.NetworkConnection -> stringProvider.getString(R.string.error_no_network) is Failure.NetworkConnection -> stringProvider.getString(R.string.error_no_network)
is Failure.ServerError -> { is Failure.ServerError -> {
throwable.error.message.takeIf { it.isNotEmpty() } throwable.error.message.takeIf { it.isNotEmpty() }
?: throwable.error.code.takeIf { it.isNotEmpty() } ?: throwable.error.code.takeIf { it.isNotEmpty() }
?: stringProvider.getString(R.string.unknown_error)
} }
else -> throwable.localizedMessage else -> throwable.localizedMessage
?: stringProvider.getString(R.string.unknown_error)
} }
?: stringProvider.getString(R.string.unknown_error)
} }
} }