Skip to content

Instantly share code, notes, and snippets.

@marrek13
Created January 16, 2022 19:28
Show Gist options
  • Save marrek13/467be212bd60c38b8883f65cca58b0b9 to your computer and use it in GitHub Desktop.
Save marrek13/467be212bd60c38b8883f65cca58b0b9 to your computer and use it in GitHub Desktop.
fun <T: Any> NetworkResponse<T, DetailsError>.call(): T {
return when (this) {
is NetworkResponse.Success<T> -> this.body
is NetworkResponse.ServerError<DetailsError> -> throw CatalogIOException(this.body?.message.orEmpty(), this.code, this.error)
is NetworkResponse.NetworkError -> throw CatalogIOException("Network error", 500, this.error)
is NetworkResponse.UnknownError -> throw CatalogIOException("Unknown error", 500, this.error)
is NetworkResponse.Error -> throw CatalogIOException("Unknown exception", 500, this.error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment