I have a flow of 2 nested request, where could be 3 different results:
- One of requests return Error
- User is not Anonymous, return Profile
- User is Anonymous, return false
Both requests could throw an error, and becaues of that implements TaskEither
const isAuth = ():TE.TaskEither<Error, E.Either<true, false>>
=> TE.tryCatch(() => Promise(...), E.toError)
const getProfile = ():TE.TaskEither<Error, Profile>
=> TE.tryCatch(() => Promise(...), E.toError)
The first request returns the boolean status of user authorization. Second request loads user profile if the user is authorized.
In return, I want to get the next signature, Error or Either with Anonymous/Profile:
E.Either<Error, E.Either<false, Profile>>
I tried to make it this way:
pipe(
isAuth()
TE.chain(item => pipe(
TE.fromEither(item),
TE.mapLeft(() => Error('Anonimous')),
TE.chain(getProfile)
))
)
But in return, I get E.Either<Error, Profile>
, witch not convenient because I have to extract Anonymous
status by hands from Error
.
How to solve that question?