Skip to content

Instantly share code, notes, and snippets.

@douglasiacovelli
Last active November 3, 2019 02:41
Show Gist options
  • Select an option

  • Save douglasiacovelli/edb8c7aca11ba3f3bfa6eaa34cb679f6 to your computer and use it in GitHub Desktop.

Select an option

Save douglasiacovelli/edb8c7aca11ba3f3bfa6eaa34cb679f6 to your computer and use it in GitHub Desktop.
fun fetchData() {
viewModelScope.launch {
val redditResponse = repository.getRedditPosts()
when (redditResponse) {
is NetworkError -> showNetworkError()
is GenericError-> showGenericError(redditResponse)
is Success -> showSuccess(redditResponse.value)
}
}
}
@Divala
Copy link

Divala commented Nov 3, 2019

How are you implementing it in activity or fragment?

@douglasiacovelli
Copy link
Author

Hi there @Divala, I've explained that on this article: “How to handle errors with Retrofit and Coroutines”: https://link.medium.com/3dBffo9Ri1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment