Skip to content

Commit

Permalink
Integrate changes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
987Nabil committed Apr 19, 2024
1 parent 0d97412 commit 318681f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
Expand Down

0 comments on commit 318681f

Please sign in to comment.