From 6a867e760cf60084729e0074c340a7a2af793b91 Mon Sep 17 00:00:00 2001 From: Jules Ivanic Date: Fri, 6 Dec 2024 03:24:43 +1100 Subject: [PATCH] Optimise `zio.http.endpoint.Endpoint.implementHandler` Replace `.map(..).catchAll(..)` with `.foldZIO` --- .../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 }