Prioritize showing error description over error

This commit is contained in:
Artem Chepurnoy 2024-01-28 08:55:12 +02:00
parent 42dab0318b
commit 97ff7e84ad
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
1 changed files with 2 additions and 3 deletions

View File

@ -199,15 +199,14 @@ fun ErrorEntity.toException(
// messages to something user-friendly. // messages to something user-friendly.
val errorTitle = kotlin.run { val errorTitle = kotlin.run {
errorModel?.message?.takeIf { it.isNotBlank() } errorModel?.message?.takeIf { it.isNotBlank() }
?: error.takeIf { it.isNotBlank() } ?: errorDescription?.takeIf { it.isNotBlank() }
// We usually should get an error message, but // We usually should get an error message, but
// just in case resort to the basic message. // just in case resort to the basic message.
?: code.description ?: "${code.description}: $error"
}.trim() }.trim()
val errorText = kotlin.run { val errorText = kotlin.run {
val validation = validationErrors?.toMap()?.format()?.takeIf { it.isNotBlank() } val validation = validationErrors?.toMap()?.format()?.takeIf { it.isNotBlank() }
val message = listOfNotNull( val message = listOfNotNull(
errorDescription?.takeIf { it.isNotBlank() },
validation, validation,
) )
.joinToString(separator = "\n") .joinToString(separator = "\n")