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 eval
ing 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.