Skip to content

Instantly share code, notes, and snippets.

@egorshustov
Created August 16, 2019 11:04
Show Gist options
  • Save egorshustov/2bb247867f7e7b1d0c835675933162bd to your computer and use it in GitHub Desktop.
Save egorshustov/2bb247867f7e7b1d0c835675933162bd to your computer and use it in GitHub Desktop.
sealed class ResponseMessage {
class Success(val message: String?) : ResponseMessage()
class Error(val message: String?, val throwable: Throwable?) : ResponseMessage()
fun getErrorMessage(): String? {
return when (this) {
is Success -> {
null
}
is Error -> {
when (this.throwable) {
is ConnectException, is TimeoutException, is UnknownHostException -> {
"Ошибка соединения: отсутствует подключение к сети или сервер недоступен"
}
else -> {
this.message ?: this.throwable.toString()
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment