diff --git a/docs/dsl/endpoint.md b/docs/dsl/endpoint.md index b36fcf164c..fa3176f378 100644 --- a/docs/dsl/endpoint.md +++ b/docs/dsl/endpoint.md @@ -255,7 +255,7 @@ object Quiz { } object EndpointWithMultipleOutputTypes extends ZIOAppDefault { - val endpoint: Endpoint[Unit, Unit, ZNothing, Either[Course, Quiz], None] = + val endpoint: Endpoint[Unit, Unit, ZNothing, Either[Quiz, Course], None] = Endpoint(RoutePattern.GET / "resources") .out[Course] .out[Quiz] @@ -264,8 +264,8 @@ object EndpointWithMultipleOutputTypes extends ZIOAppDefault { endpoint.implement(handler { ZIO.randomWith(_.nextBoolean) .map(r => - if (r) Left(Course("Introduction to Programming", 49.99)) - else Right(Quiz("What is the boiling point of water in Celsius?", 2)), + if (r) Right(Course("Introduction to Programming", 49.99)) + else Left(Quiz("What is the boiling point of water in Celsius?", 2)), ) }) .toHttpApp).provide(Server.default, Scope.default) @@ -306,7 +306,7 @@ implicit val bookSchema = DeriveSchema.gen[Book] implicit val notFoundSchema = DeriveSchema.gen[BookNotFound] implicit val authSchema = DeriveSchema.gen[AuthenticationError] -val endpoint: Endpoint[Int, (Int, Header.Authorization), Either[BookNotFound, AuthenticationError], Book, None] = +val endpoint: Endpoint[Int, (Int, Header.Authorization), Either[AuthenticationError, BookNotFound], Book, None] = Endpoint(RoutePattern.GET / "books" / PathCodec.int("id")) .header(HeaderCodec.authorization) .out[Book] diff --git a/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleErrorsUsingEither.scala b/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleErrorsUsingEither.scala index 5197c9d1ea..dbc2dbc4bd 100644 --- a/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleErrorsUsingEither.scala +++ b/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleErrorsUsingEither.scala @@ -38,7 +38,7 @@ object EndpointWithMultipleErrorsUsingEither extends ZIOAppDefault { } } - val endpoint: Endpoint[Int, (Int, Header.Authorization), Either[BookNotFound, AuthenticationError], Book, None] = + val endpoint: Endpoint[Int, (Int, Header.Authorization), Either[AuthenticationError, BookNotFound], Book, None] = Endpoint(RoutePattern.GET / "books" / PathCodec.int("id")) .header(HeaderCodec.authorization) .out[Book] @@ -48,12 +48,12 @@ object EndpointWithMultipleErrorsUsingEither extends ZIOAppDefault { def isUserAuthorized(authHeader: Header.Authorization) = false val getBookHandler - : Handler[Any, Either[BookNotFound, AuthenticationError], (RuntimeFlags, Header.Authorization), Book] = + : Handler[Any, Either[AuthenticationError, BookNotFound], (RuntimeFlags, Header.Authorization), Book] = handler { (id: Int, authHeader: Header.Authorization) => if (isUserAuthorized(authHeader)) - BookRepo.find(id).mapError(Left(_)) + BookRepo.find(id).mapError(Right(_)) else - ZIO.fail(Right(AuthenticationError("User is not authenticated", 123))) + ZIO.fail(Left(AuthenticationError("User is not authenticated", 123))) } val app = endpoint.implement(getBookHandler).toHttpApp @@ Middleware.debug diff --git a/zio-http/jvm/src/test/scala/zio/http/endpoint/BadRequestSpec.scala b/zio-http/jvm/src/test/scala/zio/http/endpoint/BadRequestSpec.scala index 9af67de883..504a32630e 100644 --- a/zio-http/jvm/src/test/scala/zio/http/endpoint/BadRequestSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/endpoint/BadRequestSpec.scala @@ -24,8 +24,8 @@ object BadRequestSpec extends ZIOSpecDefault { val expectedBody = html( body( - h1("Bad Request"), - p("There was an error decoding the request"), + h1("Codec Error"), + p("There was an error en-/decoding the request/response"), p("SchemaTransformationFailure", idAttr := "name"), p("Expected single value for query parameter age, but got 2 instead", idAttr := "message"), ),