0
votes

I'm struggling with achieving following goal: I have the API requests typed in a manner that they return either a desired value, or an error when the status code wasn't indicating success, or when the auth token has been invalid etc: Either String r.

Now, I don't want to care about it when I'm evaling my components queries. I am only interested in happy path (expected errors like invalid logon attempt is considered happy path, just want to keep unexpected stuff out of it), and the errors should be handled uniformily and globally (sending some notification to the bus).

For this, I've created transformer stack:

type App = ReaderT Env (ExceptT String (Aff AppEffects))

Now, to use it with runUI, I needed to provide natural transformation to be used with hoist (unless I'm missing other possibilities):

runApp :: Env -> App ~> Aff AppEffects
runApp env app = do
  res <- runExceptT $ runReaderT app env
  case res of
    Right r -> pure unit
    Left err -> do Bus.write err env.bus
                   -- what to return here?

Because we're using ~> here, we're forced to retain the return type, but for the Left case I don't have it at hand!

How would one tackle such requirement? To reiterate - I only want to be able to 'cancel' the evaluation of my component query when the executed action encounters an error, but I want to do it silently and handle it from the top.

2

2 Answers

1
votes

You have an exceptional case where the current thread can't continue, so the only thing to do would be to throw an exception in Aff using throwError :: forall eff a. Error -> Aff eff a.

0
votes

I came to conclusion that what I wanted to achieve was undesirable in fact. Making components query evaluation oblivious to the fact that an error have happened is nothing good (in the light that component might not be interested in handling the error fully, but at least doing something with its state to not end up broken).

Therefore, what I really need is some kind of helper that handle the error, and return a simple indication of the fact the it happened, so that component can proceed with that.