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

Lukáš Kúšik

08/12/2022, 10:17 AM
Hi! I am trying to model the error handling in our Android client. I have been inspired by this video

(1) Building applications with Kotlin and Arrow.kt in style - YouTube

, although I would like to apply these principles to the client side in this case. Let's say that there's a
Repository
which uses a
RemoteApi
and I'd like to create a new user on the backend. The
RemoteApi
does the POST call using Ktor, and returns the result of the
Either<ApiError, UserDTO>
type, where
ApiError
encapsules any network exceptions, internal server errors, etc. Now, I would like to parse expected errors (like
UserAlreadyExists
) as
UserError
of the common
DomainError
sealed type (similar to the video). I'd like the
Repository
to get the`Either<ApiError, UserDTO>` from the
RemoteApi
, process the known errors and return something like the
Either<UserError, UserDTO>
type. The problem with
Either<UserError, UserDTO>
is, that when a network exception occurs, it is an
ApiError
and not a
UserError
. The
Repository
would have to return something like
Either<Either<ApiError,UserError>, UserDTO>
which looks weird, or? So with a hierarchy like this:
Copy code
sealed interface Error
6 Views