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

Gianpaolo

10/31/2023, 9:42 AM
hi guys. sorry for this very simple question. I've just started using Retrofit and I discovered Arrow last week, so I wanted to ask you a little tip. I have a retrofit api called getUser. Would it make sense to use Either in this way?
class CustomError {
data class RetrofitError(val error: Throwable) : CustomError()
// Add other custom errors if needed
}
suspend fun getUser(): Either<CustomError, User> {
return try {
val response: Response<User> = retrofitApi.getUser()
if (response.isSuccessful) {
response.body()?.right() ?: CustomError.RetrofitError(Throwable("No user found")).left()
} else {
CustomError.RetrofitError(Throwable("Response not successful")).left()
}
} catch (e: Exception) {
CustomError.RetrofitError(e).left()
}
}
d

dave08

10/31/2023, 10:41 AM
Did you see: io.arrow-kt:arrow-core-retrofit
g

G Filippa

10/31/2023, 11:49 AM
oh no, I didnt know that
Dave, by chance are you aware of android project using arrow-core-retro? Could nt find anything on github
g

G Filippa

10/31/2023, 3:59 PM
thank you, very kind of you. 🙂
d

dave08

11/12/2023, 3:13 PM
I forgot to mention this one (the one I'm currently using): https://github.com/arrow-kt/arrow/tree/main/arrow-libs/core/arrow-core-retrofit
👍 1
g

G Filippa

11/12/2023, 4:01 PM
thanks again. I m watching some youtube presentation. Afters decades of imperative programming, it is not easy to switch, but I really like it
2 Views