Skip to content

Instantly share code, notes, and snippets.

@timusus
Last active October 20, 2018 03:58
Show Gist options
  • Save timusus/c93e1c4712d2cba08569cbb2e5316ff4 to your computer and use it in GitHub Desktop.
Save timusus/c93e1c4712d2cba08569cbb2e5316ff4 to your computer and use it in GitHub Desktop.
Error to user description
fun Error.userDescription(): String {
return when (this) {
is RemoteServiceHttpError ->
return when {
isServerError -> "A server error occurred. (${httpStatusCode.code})"
else -> "An error occurred. (${httpStatusCode.code})"
}
}
is OAuthError -> {
return "Authentication failed."
}
is NetworkError -> {
return "The server could not be reached. Please check your connection and try again."
}
is UnexpectedError -> {
return "An unexpected error occurred."
}
else -> {
return "An unknown error occurred."
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment