Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nesting routes work strange when handling errors #2823

Open
jiramares opened this issue May 6, 2024 · 2 comments
Open

Nesting routes work strange when handling errors #2823

jiramares opened this issue May 6, 2024 · 2 comments
Labels
💎 Bounty bug Something isn't working

Comments

@jiramares
Copy link

When I am nesting routes as described at https://zio.dev/zio-http/dsl/routes it works until I need call handleError.

This server:

val routes = literal("to") / Routes(
    Method.GET / "other" ->  handler(ZIO.fail(MyErrors.IdFormatError)),
    Method.GET / "do" / string("id") -> handler { (id:String, _: Request) => Response.text(s"GET /to/do/${id}") }
).handleError(_ match
    case MyErrors.IdFormatError => Response.badRequest
)

def run = Server.serve(routes.toHttpApp).provide(Server.defaultWithPort(8090))

enum MyErrors:
    case IdFormatError

When started and invoked curl -i http://localhost:8090/to/do/45 outputs:

HTTP/1.1 500 Internal Server Error
warning: 199 ZIO HTTP "Exception in thread "zio-fiber-37" java.lang.RuntimeException: Expected path segment "do" but found "
content-length: 0

But when the route leading to error (that I have to deal with) is removed:

val routes = literal("to") / Routes(
    Method.GET / "do" / string("id") -> handler { (id:String, _: Request) => Response.text(s"GET /to/do/${id}") }
)

def run = Server.serve(routes.toHttpApp).provide(Server.defaultWithPort(8090))

Everything works fine and the result of curl -i http://localhost:8090/to/do/45 is:

HTTP/1.1 200 OK
content-type: text/plain
content-length: 18

GET /to/do/45
@jiramares jiramares added the bug Something isn't working label May 6, 2024
@jdegoes
Copy link
Member

jdegoes commented Jun 5, 2024

/bounty $75 for fix and reproducer test case.

Copy link

algora-pbc bot commented Jun 5, 2024

💎 $75 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #2823 with your implementation plan
  2. Submit work: Create a pull request including /claim #2823 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bountyShare on socials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants