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
Feature Request: ResponseAs instances with error rethrown into F[_] #451
Comments
Makes sense. There are two options with the backend:
The former is more straightforward, but the latter seems closer to the true needs of the Could you maybe prepare a PR? |
Sure, I'll try to make a PR this week. |
For ZIO, something like this works fine: import sttp.client._
import sttp.client.circe.
import io.circe._
import zio._
def asJsonF[T: Decoder: IsOption]: ResponseAs[Task[T], Nothing] = asJson[T].map {
case Left(error) => Task.fail(error)
case Right(value) => Task.succeed(value)
}
sttpClient.send(req.response(asJsonF[A]).flatMap(_.body) // => ZIO[Any, Throwable, A] |
As we are extending response handling possibilities in #620 I'm not sure if it is a good idea to duplicate every possible responseAs handling with it's Since all responses can be read in a safe way into When it comes to zio if think that it will make sense to enable converting it into |
In So the original use-case would become: Similarly, |
My usecase:
F[_]
anyway..map(_.unsafeBody)
in sttp1 worked for that purpose (impure, but works forId
,Future
, or monixTask
).I can suggest having a group of
ResponseAs[F[T], _]
instances, for exampleUsage becomes
Sample implementation for
asStringF
: https://gist.github.com/xicmiah/0170570ba85c6d8d9cabec732c3cb80aNotes:
MonadError
instead, the latter isn't in implicit scope yet.FullHttpError
is only used for response body, it can be replaced with existingHttpError
The text was updated successfully, but these errors were encountered: