From 7db7f7fe556aabe4f4c3bca23c912a75f4a4ebc4 Mon Sep 17 00:00:00 2001 From: Jules Ivanic Date: Sun, 15 Dec 2024 04:59:37 +1100 Subject: [PATCH] Optimise `zio.http.endpoint.Endpoint.implementHandler` (#3236) Replace `.map(..).catchAll(..)` with `.foldZIO` Co-authored-by: Nabil Abdel-Hafeez <7283535+987Nabil@users.noreply.github.com> --- .../shared/src/main/scala/zio/http/endpoint/Endpoint.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zio-http/shared/src/main/scala/zio/http/endpoint/Endpoint.scala b/zio-http/shared/src/main/scala/zio/http/endpoint/Endpoint.scala index 7d3f094265..b1b6f6c6fc 100644 --- a/zio-http/shared/src/main/scala/zio/http/endpoint/Endpoint.scala +++ b/zio-http/shared/src/main/scala/zio/http/endpoint/Endpoint.scala @@ -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 }