Hi i thought i understood Either, then i tried emp...
# arrow
t
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
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
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