Skip to content

Instantly share code, notes, and snippets.

@labibmuhajir
Created November 11, 2021 07:45
Show Gist options
  • Save labibmuhajir/543e8e581f2d511fbb1c973a16dcb3af to your computer and use it in GitHub Desktop.
Save labibmuhajir/543e8e581f2d511fbb1c973a16dcb3af to your computer and use it in GitHub Desktop.
retrofit success data or throw
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