Created
October 8, 2019 23:59
-
-
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()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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