You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exceptions must be handled using codec, it isn't falls through and catched with Routes.handleErrorCause later.
I know that this is intentional design decision. Accessing directly to Request and Response is discouraged. However, access to these objects is necessary at least for migration purpose.
As a motivating toy example, refer to this code:
objectEndpointExampleextendsZIOAppDefault:classNoProblemException(message: String) extendsException(message)
privatevalmyEndpoint1=Endpoint(Method.GET/"my-endpoint1").query(HttpCodec.query[Option[String]]("id"))
.query(HttpCodec.query[String]("name")).out[String]
privatedefmyRoutes=Routes(
myEndpoint1.looseImplement { (maybeId: Option[String], name: String, req: Request) =>// I hope this workZIO.fail(newNoProblemException(s"my-endpoint1 $maybeId$name, requested from ${req.remoteAddress}"))
// alternatively, the code below should also work// ZIO.succeed(Response.text("OK with Response object"))
})
deferrorProcessor(cause: Cause[Any]):Response=
cause.failureOrCause matchcaseLeft(failure) => failure matchcasei: NoProblemException=>Response.json(s"""{"message": "${i.getMessage}"}""")
casei: Throwable=>Response.text("My custom response")
caseRight(cause) =>Response.fromCause(cause)
defrun:ZIO[Any, Throwable, Any] =Server.serve(myRoutes.handleErrorCause(errorProcessor)).provide(Server.default)
I hope a new method Endpoint.looseImplement would provide this generous access to Request, Response, and ZIO.fail handling from Routes.handleErrorCause.
The text was updated successfully, but these errors were encountered:
When I tried migrate my imperative style
Route
implementations to declarative style, I was frustrated by:Request
objectResponse
objectRoutes.handleErrorCause
later.I know that this is intentional design decision. Accessing directly to
Request
andResponse
is discouraged. However, access to these objects is necessary at least for migration purpose.As a motivating toy example, refer to this code:
I hope a new method
Endpoint.looseImplement
would provide this generous access toRequest
,Response
, andZIO.fail
handling fromRoutes.handleErrorCause
.The text was updated successfully, but these errors were encountered: