https://kotlinlang.org logo
#arrow
Title
# arrow
t

Tower Guidev2

07/11/2022, 11:05 AM
Hi i thought i understood Either, then i tried employing
io.arrow-kt:arrow-core-retrofit
in my android application 🤦‍♂️
previously i was checking
Copy code
if (response.isSuccessful && response.code() == HttpURLConnection.HTTP_OK) {
} else manageHTTPError(response)
where response is
retrofit2.Response
How do I get to check the same values when I refactor to this
Copy code
Either<NetworkException, Response<UserInfoResponse>>
in my retrofit API interface?
s

stojan

07/11/2022, 11:47 AM
the way to use it is:
Either<ErrorBody, SuccessBody>
2xx response codes get deserialised into
SuccessBody
and other HTTP codes (errors) get deserialised into
ErrorBody
other errors (e.g.
IOException
) still throw
t

Tower Guidev2

07/12/2022, 8:14 AM
what about the case when I need to detect a certain HTTP code though?, such as 204 for my internet connectivity test network call to
Copy code
private const val GOOGLE_CONNECTIVITY_CHECK_URL = "<https://connectivitycheck.gstatic.com/generate_204>"
in that case you can use
ResponseE<ErrorBody, SuccessBody>
where
ResponseE
is like
Response
from retrofit but has an
Either
for success/error
👍 1
🙌 1
5 Views