zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

Error recovery behavior is not clear

Open soujiro32167 opened this issue 3 years ago • 4 comments
trafficstars

Describe the bug

  1. It is not clear what Server.error is supposed to do. Does it recover from errors, or is it a .tap on them?
  2. It does not work either way...
  3. 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

  1. The error handler should have printed its content
  2. By default, the error handler should be more graceful, e.g. return error 500 with Internal Server Error message
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

soujiro32167 avatar Feb 14 '22 19:02 soujiro32167

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.

tusharmath avatar Feb 15 '22 09:02 tusharmath

Oh I see, an error thrown by Netty?

soujiro32167 avatar Feb 15 '22 16:02 soujiro32167

Oh I see, an error thrown by Netty?

yes

amitksingh1490 avatar Feb 15 '22 19:02 amitksingh1490

@soujiro32167 would you be willing to create a PR to rename the method to onError and update the scala doc :)

tusharmath avatar Feb 20 '22 13:02 tusharmath

Picked it up

adrianfilip avatar Sep 12 '22 06:09 adrianfilip