antiope-core 7.4.5 → 7.5.0
raw patch · 2 files changed
+17/−10 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Antiope.Core.Error: handleServiceError :: MonadAWS m => m a -> (a -> b) -> (Status -> Maybe b) -> m b
Files
- antiope-core.cabal +1/−1
- src/Antiope/Core/Error.hs +16/−9
antiope-core.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.4 name: antiope-core-version: 7.4.5+version: 7.5.0 description: Please see the README on Github at <https://github.com/arbor/antiope#readme>. synopsis: Please see the README on Github at <https://github.com/arbor/antiope#readme> category: Services
src/Antiope/Core/Error.hs view
@@ -1,22 +1,29 @@+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-} module Antiope.Core.Error ( handle404ToNone+ , handleServiceError ) where import Control.Monad.Catch (catch, throwM) import Network.AWS (Error (..), MonadAWS, ServiceError (..)) import Network.HTTP.Types.Status (Status (..)) -import qualified Data.ByteString.Lazy as LBS- handle404ToNone :: MonadAWS m => m a -> m (Maybe a)-handle404ToNone f = do- ebs <- (Right <$> f) `catch` \(err :: Error) -> case err of- (ServiceError (ServiceError' _ (Status 404 _) _ _ _ _)) -> return (Left LBS.empty)- _ -> throwM err- case ebs of- Right bs -> return (Just bs)- Left _ -> return Nothing+handle404ToNone f =+ handleServiceError f Just $ \case+ (Status 404 _) -> Just Nothing+ _ -> Nothing++handleServiceError :: MonadAWS m+ => m a -- ^ AWS action+ -> (a -> b) -- ^ Transform successful result+ -> (Status -> Maybe b) -- ^ Compensate with the failure. 'Nothing' means that the error is not handled+ -> m b -- ^ Final result. In case of unhandled errors the exception is re-thrown.+handleServiceError ma success failure =+ (success <$> ma) `catch` \(err :: Error) -> case err of+ (ServiceError (ServiceError' _ status _ _ _ _)) -> maybe (throwM err) pure (failure status)+ _ -> throwM err