module Ecluse.Runtime.Aws.Fault (
classifyAwsTransport,
sendClassified,
) where
import Amazonka qualified as AWS
import Control.Monad.Trans.Resource (runResourceT)
import Ecluse.Core.Fault (TransportCause (TransportProtocol), TransportFault, transportFault)
import Ecluse.Core.Fault.Http (classifyTransport)
import Ecluse.Core.Text (displayExceptionT)
classifyAwsTransport :: AWS.Error -> TransportFault
classifyAwsTransport :: Error -> TransportFault
classifyAwsTransport = \case
AWS.TransportError HttpException
httpErr -> HttpException -> TransportFault
classifyTransport HttpException
httpErr
Error
err -> TransportCause -> Text -> TransportFault
transportFault TransportCause
TransportProtocol (Error -> Text
forall e. Exception e => e -> Text
displayExceptionT Error
err)
sendClassified ::
(AWS.AWSRequest a) =>
(AWS.Error -> e) ->
AWS.Env ->
a ->
IO (Either e (AWS.AWSResponse a))
sendClassified :: forall a e.
AWSRequest a =>
(Error -> e) -> Env -> a -> IO (Either e (AWSResponse a))
sendClassified Error -> e
classify Env
env = (Either Error (AWSResponse a) -> Either e (AWSResponse a))
-> IO (Either Error (AWSResponse a))
-> IO (Either e (AWSResponse a))
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Error -> e)
-> Either Error (AWSResponse a) -> Either e (AWSResponse a)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first Error -> e
classify) (IO (Either Error (AWSResponse a))
-> IO (Either e (AWSResponse a)))
-> (a -> IO (Either Error (AWSResponse a)))
-> a
-> IO (Either e (AWSResponse a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ResourceT IO (Either Error (AWSResponse a))
-> IO (Either Error (AWSResponse a))
forall (m :: * -> *) a. MonadUnliftIO m => ResourceT m a -> m a
runResourceT (ResourceT IO (Either Error (AWSResponse a))
-> IO (Either Error (AWSResponse a)))
-> (a -> ResourceT IO (Either Error (AWSResponse a)))
-> a
-> IO (Either Error (AWSResponse a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Env -> a -> ResourceT IO (Either Error (AWSResponse a))
forall (m :: * -> *) a.
(MonadResource m, AWSRequest a) =>
Env -> a -> m (Either Error (AWSResponse a))
AWS.sendEither Env
env