Created
November 11, 2021 07:45
-
-
Save labibmuhajir/543e8e581f2d511fbb1c973a16dcb3af to your computer and use it in GitHub Desktop.
retrofit success data or throw
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 : Any> Response<*>.bodyOrThrow(): T { | |
if (isSuccessful && (code() == 200 || code() == 201)) return body() as T | |
else throw Exception() //or with custom exception | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment