zio-http
zio-http copied to clipboard
Accept Routes with arbitrary error type in `PathCodec#/`
Is your feature request related to a problem? Please describe.
Currently, PathCodec#/
requires the Routes
passed to it to have the errors handled and/or mapped to Response
.
This limits where it can be used, as someone may want to handle the errors at a later point.
//> using dep dev.zio::zio-http:3.0.0-RC8
import zio.*
import zio.http.*
import zio.http.codec.PathCodec.literal
object Application extends ZIOAppDefault:
val routes: Routes[Any, NotImplementedError] =
literal("welcome") / Routes(
Method.GET / Root -> handler:
ZIO.fail(NotImplementedError())
)
def run =
Server
.serve(routes.sandbox)
.provide(Server.default)
This code fails to compile with the error:
[error] None of the overloaded alternatives of method / in trait PathCodec with types
[error] [Env]
[error] (routes: zio.http.Routes[Env, zio.http.Response])
[error] (implicit ev: zio.http.codec.PathCodec[Unit] <:<
[error] zio.http.codec.PathCodec[Unit]): zio.http.Routes[Env, zio.http.Response]
[error] [B]
[error] (that: zio.http.codec.PathCodec[B])
[error] (implicit combiner: zio.http.codec.Combiner[Unit, B]):
[error] zio.http.codec.PathCodec[combiner.Out]
[error] match arguments (zio.http.Routes[Any, NotImplementedError])
[error] literal("welcome") / Routes(
[error] ^^^^^^^^^^^^^^^^^^^^
Describe the solution you'd like
It would be preferable not to force the user to handle the errors at this point and have the above code compile successfully.