Created
August 16, 2019 11:04
-
-
Save egorshustov/2bb247867f7e7b1d0c835675933162bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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