Hi, I'm trying to handle errors gracefully. Imagine the following scenario
import cats.data.EitherT
import japgolly.scalajs.react.{Callback, React}
import japgolly.scalajs.react.callback.AsyncCallback
import japgolly.scalajs.react.callback.CallbackCats._
case class Data(name: String, age: Int)
val httpRequest: AsyncCallback[Data] = ???
val handledGracefully: AsyncCallback[Unit] =
EitherT
.liftF[F, Throwable, Data](httpRequest)
.semiFlatTap(d => Callback.log(s"all good, data is $d").async)
.leftSemiflatTap(err => Callback.log(s"ooops, ${err.getMessage}").async)
.merge
I would expect the above to be handled gracefully, but I'm seeing errors being raised.
Notes
the httpRequest implementation validates the status code this way:
.validateStatusIsSuccessful(Callback.throwException) // validateStatusIsSuccessful method from AjaxF class
I'm also parsing the response with circe, so there are a few things that could go wrong as part of the request, but I would expect any error to be caught and handled gracefully, instead I'm seeing unhandled errors in the js console.
if I change the httpRequest to return an AsyncCallback[Either[Throwable, Data]] removing parsing logic (with circe) and the status validation logic (explained above), then the handledGracefully val behave as expected
I was wondering if this (cats + callback) is the expected behaviour, since it is different from cats + cats effect,
Hi, I'm trying to handle errors gracefully. Imagine the following scenario
I would expect the above to be handled gracefully, but I'm seeing errors being raised.
Notes
the
httpRequest
implementation validates the status code this way:.validateStatusIsSuccessful(Callback.throwException) // validateStatusIsSuccessful method from AjaxF class
I'm also parsing the response with
circe
, so there are a few things that could go wrong as part of the request, but I would expect any error to be caught and handled gracefully, instead I'm seeing unhandled errors in the js console.httpRequest
to return an AsyncCallback[Either[Throwable, Data]] removing parsing logic (with circe) and the status validation logic (explained above), then thehandledGracefully
val behave as expectedI was wondering if this (
cats
+callback
) is the expected behaviour, since it is different fromcats
+cats effect
,Thank you