Gianpaolo
10/31/2023, 9:42 AMclass 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()
}
}
dave08
10/31/2023, 10:41 AMG Filippa
10/31/2023, 11:49 AMdave08
10/31/2023, 3:58 PMG Filippa
10/31/2023, 3:59 PMdave08
11/12/2023, 3:13 PMG Filippa
11/12/2023, 4:01 PM