tapir icon indicating copy to clipboard operation
tapir copied to clipboard

[improvement] zio-http integration not comfortable failed effect usages

Open kuzkdmy opened this issue 3 years ago • 1 comments

Tapir version: 0.19.3

From contract programming all looks good, but it becomes quite uncomfortable with latest update

zio-http integration not comfortable failed effect usages

Exsisting tapir library code ` implicit class RichZEndpoint[A, I, E, O, C](e: Endpoint[A, I, E, O, C]) {

def zServerLogic[R](logic: I => ZIO[R, E, O])(implicit aIsUnit: A =:= Unit): ZServerEndpoint[R, C] =
  ServerEndpoint.public(e.asInstanceOf[Endpoint[Unit, I, E, O, C]], _ => logic(_: I).either.resurrect)

def zServerSecurityLogic[R, U](f: A => ZIO[R, E, U]): ZPartialServerEndpoint[R, A, U, I, E, O, C] =
  ZPartialServerEndpoint(e, f)

}`

See logic ZIO[_ , E, _] contract forces to be with same error channel as Endpoint E if endpoint don't declare error E is Unit and clients can not use Task[O] and have manually describe in all places InternalServerError

kuzkdmy avatar Jan 22 '22 20:01 kuzkdmy

Would you prefer to work with def zServerLogic[R](logic: I => Task[Either[E, O]])?

Maybe we could provide def zServerLogicFallible[R](logic: I => RIO[Either[E, O]]), would that work?

adamw avatar Jan 28 '22 15:01 adamw