Skip to content

Instantly share code, notes, and snippets.

@demonar
Created October 8, 2019 23:59
Show Gist options
  • Save demonar/c36b8dac07f68189fb37caabe435874b to your computer and use it in GitHub Desktop.
Save demonar/c36b8dac07f68189fb37caabe435874b to your computer and use it in GitHub Desktop.
This method adds an extension to retrofit to return a Result<T> from execute()
inline fun <reified T> Call<T>.executeForResult(): Result<T> {
return try {
val response = execute()
Result.Success(this, response)
} catch (e: Exception) {
Result.Failure(this, e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment