https://kotlinlang.org logo
#android
Title
# android
k

Kulwinder Singh

09/13/2019, 11:52 AM
In my api response there is field called
isSuccess
to see if
post
or any other request is success or not. so thats why it return result OK(200) even if i have sent invalid values, so in above extension function on
Response
can i check
isSuccess
variable from original
json
? Note: this extension function is called on
Response
from retrofit
l

Luca Nicoletti

09/13/2019, 12:19 PM
You have to check if the
Response.body
you’re receiving is of the type you’re looking for:
YourResponse
and then perform the check 🙂
Something like:
if (response.body() is YourResponse && response.body().isSuccess)
Be aware though that calling
response.body()
will consume it, so better save it in a var
31 Views