Skip to content

Instantly share code, notes, and snippets.

@chizoba
Created August 6, 2018 08:24
Show Gist options
  • Select an option

  • Save chizoba/b93f4f54b9e5ca2da69973fb9e872bae to your computer and use it in GitHub Desktop.

Select an option

Save chizoba/b93f4f54b9e5ca2da69973fb9e872bae to your computer and use it in GitHub Desktop.
Kobserver's onException() implementation
GitHubRequest(name).doRequest().observe(this, object : Kobserver<ResponseModel>() {
override fun onException(exception: Exception) {
// handle exception here
when(exception){
is GitHubErrorHandler.ErrorConfig.NetworkException -> {
Toast.makeText(this@MainActivity, exception.message, Toast.LENGTH_LONG).show()
}
is GitHubErrorHandler.ErrorConfig.GitHubException -> {
Toast.makeText(this@MainActivity, exception.message, Toast.LENGTH_LONG).show()
}
else -> Toast.makeText(this@MainActivity, "Oops! Something went wrong.", Toast.LENGTH_LONG).show()
}
}
override fun onSuccess(data: ResponseModel) {
// update UI
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment