From a440dcbb89f74b607720bb5805390749861f9fe5 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 3 Mar 2020 14:50:18 +0100 Subject: rewrite handleUpload This way we avoid the right-drift that we introduced in the first version, as the error handling and propagation is done in the Maybe monad. The downside to this is that we lose some error information: We cannot show anymore if the authorization failed or something else went wrong, because in all cases we just bail out with Nothing. --- src/ImageHoster/Monad.hs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/ImageHoster') diff --git a/src/ImageHoster/Monad.hs b/src/ImageHoster/Monad.hs index a05d59d..198ebd5 100644 --- a/src/ImageHoster/Monad.hs +++ b/src/ImageHoster/Monad.hs @@ -7,6 +7,7 @@ module ImageHoster.Monad , FallibleApp -- * Conversion functions , runFallibleApp + , fallible , liftApp , run -- * Data accessors @@ -54,6 +55,11 @@ runFallibleApp :: FallibleApp a -> App (Maybe a) runFallibleApp = runMaybeT +-- | Ensure that a computation that can fail runs as a 'FallibleApp'. +fallible :: App (Maybe a) -> FallibleApp a +fallible = MaybeT + + -- | Lift an 'App' to a 'FallibleApp' that never fails. liftApp :: App a -> FallibleApp a liftApp a = MaybeT $ Just <$> a -- cgit v1.2.3