Skip to content

Commit

Permalink
Optimise zio.http.endpoint.Endpoint.implementHandler (#3236)
Browse files Browse the repository at this point in the history
Replace `.map(..).catchAll(..)` with `.foldZIO`

Co-authored-by: Nabil Abdel-Hafeez <[email protected]>
  • Loading branch information
guizmaii and 987Nabil authored Dec 14, 2024
1 parent 869a230 commit 7db7f7f
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,10 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
)
.getOrElse(defaultMediaTypes)
(endpoint.input ++ authCodec(endpoint.authType)).decodeRequest(request, config).orDie.flatMap { value =>
original(value).map(endpoint.output.encodeResponse(_, outputMediaTypes, config)).catchAll { error =>
ZIO.succeed(endpoint.error.encodeResponse(error, outputMediaTypes, config))
}
original(value).foldZIO(
success = output => Exit.succeed(endpoint.output.encodeResponse(output, outputMediaTypes, config)),
failure = error => Exit.succeed(endpoint.error.encodeResponse(error, outputMediaTypes, config)),
)
}
} -> condition
}
Expand Down

0 comments on commit 7db7f7f

Please sign in to comment.