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 {
return when (throwable) {
null -> ""
null -> null
is Failure.NetworkConnection -> stringProvider.getString(R.string.error_no_network)
is Failure.ServerError -> {
throwable.error.message.takeIf { it.isNotEmpty() }
?: throwable.error.code.takeIf { it.isNotEmpty() }
?: stringProvider.getString(R.string.unknown_error)
?: throwable.error.code.takeIf { it.isNotEmpty() }
}
else -> throwable.localizedMessage
?: stringProvider.getString(R.string.unknown_error)
}
?: stringProvider.getString(R.string.unknown_error)
}
}