zio-http
zio-http copied to clipboard
Error recovery behavior is not clear
Describe the bug
- It is not clear what
Server.erroris supposed to do. Does it recover from errors, or is it a.tapon them? - It does not work either way...
- By default, not recovering from an error results in fiber death
To Reproduce
val app =
Http.collectZIO[Request] {
case Method.GET -> !! / "foo" => ZIO.fail(new Throwable("boom"))
}
Server.app(app).withPort(9090).withError(e => ZIO.debug(s"an error happened: $e")).make <*> AsyncHttpClientZioBackend.managed() use { case (_, backend) =>
basicRequest.get(uri"http://localhost:9090/foo").send(backend).debug
}
// result: a 500 response with fiber trace
Response(Left(<html><head></head><body><h1>Internal Server Error</h1><pre><div>java.lang.Throwable: boom
at <REDACTED>)
at zio.ZIO$.$anonfun$fail$1(ZIO.scala:2898)
at zio.internal.FiberContext.evaluateNow(FiberContext.scala:413)
at zio.internal.FiberContext.$anonfun$fork$17(FiberContext.scala:781)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)</div></pre></body></html>),500,Internal Server Error,List(content-length: 700),List(),RequestMetadata(GET,http://localhost:9090/foo,Vector(Accept-Encoding: gzip, deflate)))
Expected behaviour
- The error handler should have printed its content
- By default, the error handler should be more graceful, e.g. return error 500 with
Internal Server Errormessage
val recover = Http.error("Internal Server Error")
Server.app(app orElse recover)...
Additional context Scala version: 2.13.7 zio-http version: 1.0.0-RC23 zio version: 1.0.13
I think the name of the function should be changed. The function is called for whenever there is an internal error. Something that is beyond the scope of a typical request response cycle.
Oh I see, an error thrown by Netty?
Oh I see, an error thrown by Netty?
yes
@soujiro32167 would you be willing to create a PR to rename the method to onError and update the scala doc :)
Picked it up