Skip to content

Instantly share code, notes, and snippets.

@naturalwarren
Last active January 24, 2019 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naturalwarren/c96fd674b0b91e24c117ef1f263d793f to your computer and use it in GitHub Desktop.
Save naturalwarren/c96fd674b0b91e24c117ef1f263d793f to your computer and use it in GitHub Desktop.
Making a Retrofit API call with RxJava with a Kotlin-esque API
authApi.getTokens()
.subscribe { response : NetworkResponse<AccessToken, Error> ->
when (response) {
is NetworkResponse.Success<AccessToken> -> {
// A 2XX response that's guaranteed to have a body of type AccessToken.
}
is NetworkResponse.ServerError<Error> -> {
// A non-2XX response that may have an Error as its error body.
}
is NetworkResponse.NetworkError -> {
// A request that didn't result in a response from the server.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment