module Ecluse.Runtime.Aws.Fault (
classifyAwsTransport,
classifyEscapedTransport,
sendClassified,
foldTransportEscapes,
serviceStatus,
AwsRequestFailed (..),
AwsParty (..),
AwsFault (..),
AwsAnswer (..),
sendRaising,
retypeAwsFailure,
AwsCredentialFault (..),
retypeAmazonkaEscapes,
displayAwsFaultT,
errorCodeText,
) where
import Amazonka qualified as AWS
import Amazonka.Auth.Exception (AuthError (..))
import Control.Monad.Trans.Resource (runResourceT)
import Data.Text qualified as T
import Lens.Micro ((^.))
import Network.HTTP.Client qualified as HTTP
import Network.HTTP.Types.Status (statusCode)
import UnliftIO (MonadUnliftIO)
import UnliftIO.Exception (throwIO, tryJust)
import Ecluse.Core.Fault (HttpFault (HttpStatus), TransportCause (TransportProtocol), TransportFault, boundedDetail, renderHttpFault, transportFault)
import Ecluse.Core.Fault.Http (classifyTransport, displayFaultT, hostPortLabel, httpFault)
classifyAwsTransport :: AWS.Error -> TransportFault
classifyAwsTransport :: Error -> TransportFault
classifyAwsTransport = \case
AWS.TransportError HttpException
httpErr -> HttpException -> TransportFault
classifyTransport HttpException
httpErr
AWS.ServiceError ServiceError
service -> TransportCause -> Text -> TransportFault
transportFault TransportCause
TransportProtocol (Text -> AwsAnswer -> Text
renderAnswer (ServiceError -> Text
serviceName ServiceError
service) (ServiceError -> AwsAnswer
serviceAnswer ServiceError
service))
AWS.SerializeError SerializeError
failure -> TransportCause -> Text -> TransportFault
transportFault TransportCause
TransportProtocol (Text -> Int -> Text
renderUndecodable (SerializeError
failure SerializeError -> Getting Text SerializeError Text -> Text
forall s a. s -> Getting a s a -> a
^. (Abbrev -> Const Text Abbrev)
-> SerializeError -> Const Text SerializeError
Lens' SerializeError Abbrev
AWS.serializeError_abbrev ((Abbrev -> Const Text Abbrev)
-> SerializeError -> Const Text SerializeError)
-> ((Text -> Const Text Text) -> Abbrev -> Const Text Abbrev)
-> Getting Text SerializeError Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Const Text Text) -> Abbrev -> Const Text Abbrev
Iso' Abbrev Text
AWS._Abbrev) (SerializeError -> Int
undecodableStatus SerializeError
failure))
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
classifyEscapedTransport :: SomeException -> Maybe TransportFault
classifyEscapedTransport :: SomeException -> Maybe TransportFault
classifyEscapedTransport SomeException
err
| Just HttpException
http <- SomeException -> Maybe HttpException
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
err = TransportFault -> Maybe TransportFault
forall a. a -> Maybe a
Just (HttpException -> TransportFault
classifyTransport HttpException
http)
| Just Error
aws <- SomeException -> Maybe Error
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
err = TransportFault -> Maybe TransportFault
forall a. a -> Maybe a
Just (Error -> TransportFault
classifyAwsTransport Error
aws)
| Bool
otherwise = Maybe TransportFault
forall a. Maybe a
Nothing
foldTransportEscapes :: (TransportFault -> fault) -> IO (Either fault a) -> IO (Either fault a)
foldTransportEscapes :: forall fault a.
(TransportFault -> fault)
-> IO (Either fault a) -> IO (Either fault a)
foldTransportEscapes TransportFault -> fault
inject IO (Either fault a)
action =
(SomeException -> Maybe TransportFault)
-> IO (Either fault a)
-> IO (Either TransportFault (Either fault a))
forall (m :: * -> *) e b a.
(MonadUnliftIO m, Exception e) =>
(e -> Maybe b) -> m a -> m (Either b a)
tryJust SomeException -> Maybe TransportFault
classifyEscapedTransport IO (Either fault a)
action IO (Either TransportFault (Either fault a))
-> (Either TransportFault (Either fault a) -> IO (Either fault a))
-> IO (Either fault a)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (TransportFault -> IO (Either fault a))
-> (Either fault a -> IO (Either fault a))
-> Either TransportFault (Either fault a)
-> IO (Either fault a)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Either fault a -> IO (Either fault a)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either fault a -> IO (Either fault a))
-> (TransportFault -> Either fault a)
-> TransportFault
-> IO (Either fault a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. fault -> Either fault a
forall a b. a -> Either a b
Left (fault -> Either fault a)
-> (TransportFault -> fault) -> TransportFault -> Either fault a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TransportFault -> fault
inject) Either fault a -> IO (Either fault a)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
serviceStatus :: AWS.Error -> Maybe Int
serviceStatus :: Error -> Maybe Int
serviceStatus = \case
AWS.ServiceError ServiceError
err -> Int -> Maybe Int
forall a. a -> Maybe a
Just (Status -> Int
statusCode (ServiceError
err ServiceError -> Getting Status ServiceError Status -> Status
forall s a. s -> Getting a s a -> a
^. Getting Status ServiceError Status
Lens' ServiceError Status
AWS.serviceError_status))
Error
_ -> Maybe Int
forall a. Maybe a
Nothing
data AwsRequestFailed = AwsRequestFailed
{ AwsRequestFailed -> AwsParty
arfParty :: AwsParty
, AwsRequestFailed -> AwsFault
arfFault :: AwsFault
}
deriving stock (AwsRequestFailed -> AwsRequestFailed -> Bool
(AwsRequestFailed -> AwsRequestFailed -> Bool)
-> (AwsRequestFailed -> AwsRequestFailed -> Bool)
-> Eq AwsRequestFailed
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AwsRequestFailed -> AwsRequestFailed -> Bool
== :: AwsRequestFailed -> AwsRequestFailed -> Bool
$c/= :: AwsRequestFailed -> AwsRequestFailed -> Bool
/= :: AwsRequestFailed -> AwsRequestFailed -> Bool
Eq, Int -> AwsRequestFailed -> ShowS
[AwsRequestFailed] -> ShowS
AwsRequestFailed -> FilePath
(Int -> AwsRequestFailed -> ShowS)
-> (AwsRequestFailed -> FilePath)
-> ([AwsRequestFailed] -> ShowS)
-> Show AwsRequestFailed
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AwsRequestFailed -> ShowS
showsPrec :: Int -> AwsRequestFailed -> ShowS
$cshow :: AwsRequestFailed -> FilePath
show :: AwsRequestFailed -> FilePath
$cshowList :: [AwsRequestFailed] -> ShowS
showList :: [AwsRequestFailed] -> ShowS
Show)
instance Exception AwsRequestFailed where
displayException :: AwsRequestFailed -> FilePath
displayException = Text -> FilePath
forall a. ToString a => a -> FilePath
toString (Text -> FilePath)
-> (AwsRequestFailed -> Text) -> AwsRequestFailed -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AwsRequestFailed -> Text
renderRequestFailed
data AwsParty
=
AwsEndpointAt Text Int
|
AwsServiceNamed Text
deriving stock (AwsParty -> AwsParty -> Bool
(AwsParty -> AwsParty -> Bool)
-> (AwsParty -> AwsParty -> Bool) -> Eq AwsParty
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AwsParty -> AwsParty -> Bool
== :: AwsParty -> AwsParty -> Bool
$c/= :: AwsParty -> AwsParty -> Bool
/= :: AwsParty -> AwsParty -> Bool
Eq, Int -> AwsParty -> ShowS
[AwsParty] -> ShowS
AwsParty -> FilePath
(Int -> AwsParty -> ShowS)
-> (AwsParty -> FilePath) -> ([AwsParty] -> ShowS) -> Show AwsParty
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AwsParty -> ShowS
showsPrec :: Int -> AwsParty -> ShowS
$cshow :: AwsParty -> FilePath
show :: AwsParty -> FilePath
$cshowList :: [AwsParty] -> ShowS
showList :: [AwsParty] -> ShowS
Show)
data AwsFault
=
AwsStatus AwsAnswer
|
AwsUndecodable Int
|
AwsHttp HttpFault
deriving stock (AwsFault -> AwsFault -> Bool
(AwsFault -> AwsFault -> Bool)
-> (AwsFault -> AwsFault -> Bool) -> Eq AwsFault
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AwsFault -> AwsFault -> Bool
== :: AwsFault -> AwsFault -> Bool
$c/= :: AwsFault -> AwsFault -> Bool
/= :: AwsFault -> AwsFault -> Bool
Eq, Int -> AwsFault -> ShowS
[AwsFault] -> ShowS
AwsFault -> FilePath
(Int -> AwsFault -> ShowS)
-> (AwsFault -> FilePath) -> ([AwsFault] -> ShowS) -> Show AwsFault
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AwsFault -> ShowS
showsPrec :: Int -> AwsFault -> ShowS
$cshow :: AwsFault -> FilePath
show :: AwsFault -> FilePath
$cshowList :: [AwsFault] -> ShowS
showList :: [AwsFault] -> ShowS
Show)
data AwsAnswer = AwsAnswer
{ AwsAnswer -> Int
aaStatus :: Int
, AwsAnswer -> Text
aaCode :: Text
, AwsAnswer -> Maybe Text
aaRequestId :: Maybe Text
, AwsAnswer -> Maybe Text
aaMessage :: Maybe Text
}
deriving stock (AwsAnswer -> AwsAnswer -> Bool
(AwsAnswer -> AwsAnswer -> Bool)
-> (AwsAnswer -> AwsAnswer -> Bool) -> Eq AwsAnswer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AwsAnswer -> AwsAnswer -> Bool
== :: AwsAnswer -> AwsAnswer -> Bool
$c/= :: AwsAnswer -> AwsAnswer -> Bool
/= :: AwsAnswer -> AwsAnswer -> Bool
Eq, Int -> AwsAnswer -> ShowS
[AwsAnswer] -> ShowS
AwsAnswer -> FilePath
(Int -> AwsAnswer -> ShowS)
-> (AwsAnswer -> FilePath)
-> ([AwsAnswer] -> ShowS)
-> Show AwsAnswer
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AwsAnswer -> ShowS
showsPrec :: Int -> AwsAnswer -> ShowS
$cshow :: AwsAnswer -> FilePath
show :: AwsAnswer -> FilePath
$cshowList :: [AwsAnswer] -> ShowS
showList :: [AwsAnswer] -> ShowS
Show)
sendRaising :: (AWS.AWSRequest a) => AWS.Env -> a -> IO (AWS.AWSResponse a)
sendRaising :: forall a. AWSRequest a => Env -> a -> IO (AWSResponse a)
sendRaising Env
env a
request = (Error -> SomeException)
-> Env -> a -> IO (Either SomeException (AWSResponse a))
forall a e.
AWSRequest a =>
(Error -> e) -> Env -> a -> IO (Either e (AWSResponse a))
sendClassified ((Text -> AwsParty) -> Error -> SomeException
raised (AwsParty -> Text -> AwsParty
forall a b. a -> b -> a
const (Env -> a -> AwsParty
forall a. AWSRequest a => Env -> a -> AwsParty
requestEndpoint Env
env a
request))) Env
env a
request IO (Either SomeException (AWSResponse a))
-> (Either SomeException (AWSResponse a) -> IO (AWSResponse a))
-> IO (AWSResponse a)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (SomeException -> IO (AWSResponse a))
-> (AWSResponse a -> IO (AWSResponse a))
-> Either SomeException (AWSResponse a)
-> IO (AWSResponse a)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> IO (AWSResponse a)
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO AWSResponse a -> IO (AWSResponse a)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
retypeAwsFailure :: IO a -> IO a
retypeAwsFailure :: forall a. IO a -> IO a
retypeAwsFailure IO a
action =
(SomeException -> Maybe SomeException)
-> IO a -> IO (Either SomeException a)
forall (m :: * -> *) e b a.
(MonadUnliftIO m, Exception e) =>
(e -> Maybe b) -> m a -> m (Either b a)
tryJust SomeException -> Maybe SomeException
awsCallFault IO a
action IO (Either SomeException a)
-> (Either SomeException a -> IO a) -> IO a
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (SomeException -> IO a)
-> (a -> IO a) -> Either SomeException a -> IO a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> IO a
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO a -> IO a
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
data AwsCredentialFault
=
AwsCredentialMissing Text
|
AwsCredentialUnusable Text
|
AwsCredentialsExhausted
deriving stock (AwsCredentialFault -> AwsCredentialFault -> Bool
(AwsCredentialFault -> AwsCredentialFault -> Bool)
-> (AwsCredentialFault -> AwsCredentialFault -> Bool)
-> Eq AwsCredentialFault
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AwsCredentialFault -> AwsCredentialFault -> Bool
== :: AwsCredentialFault -> AwsCredentialFault -> Bool
$c/= :: AwsCredentialFault -> AwsCredentialFault -> Bool
/= :: AwsCredentialFault -> AwsCredentialFault -> Bool
Eq, Int -> AwsCredentialFault -> ShowS
[AwsCredentialFault] -> ShowS
AwsCredentialFault -> FilePath
(Int -> AwsCredentialFault -> ShowS)
-> (AwsCredentialFault -> FilePath)
-> ([AwsCredentialFault] -> ShowS)
-> Show AwsCredentialFault
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AwsCredentialFault -> ShowS
showsPrec :: Int -> AwsCredentialFault -> ShowS
$cshow :: AwsCredentialFault -> FilePath
show :: AwsCredentialFault -> FilePath
$cshowList :: [AwsCredentialFault] -> ShowS
showList :: [AwsCredentialFault] -> ShowS
Show)
instance Exception AwsCredentialFault where
displayException :: AwsCredentialFault -> FilePath
displayException = Text -> FilePath
forall a. ToString a => a -> FilePath
toString (Text -> FilePath)
-> (AwsCredentialFault -> Text) -> AwsCredentialFault -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AwsCredentialFault -> Text
renderCredentialFault
retypeAmazonkaEscapes :: (MonadUnliftIO m) => m a -> m a
retypeAmazonkaEscapes :: forall (m :: * -> *) a. MonadUnliftIO m => m a -> m a
retypeAmazonkaEscapes m a
action = (SomeException -> Maybe SomeException)
-> m a -> m (Either SomeException a)
forall (m :: * -> *) e b a.
(MonadUnliftIO m, Exception e) =>
(e -> Maybe b) -> m a -> m (Either b a)
tryJust SomeException -> Maybe SomeException
amazonkaFault m a
action m (Either SomeException a)
-> (Either SomeException a -> m a) -> m a
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (SomeException -> m a)
-> (a -> m a) -> Either SomeException a -> m a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> m a
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO a -> m a
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
displayAwsFaultT :: SomeException -> Text
displayAwsFaultT :: SomeException -> Text
displayAwsFaultT SomeException
err = SomeException -> Text
displayFaultT (SomeException -> Maybe SomeException -> SomeException
forall a. a -> Maybe a -> a
fromMaybe SomeException
err (SomeException -> Maybe SomeException
amazonkaFault SomeException
err))
amazonkaFault :: SomeException -> Maybe SomeException
amazonkaFault :: SomeException -> Maybe SomeException
amazonkaFault SomeException
err
| Just Error
awsErr <- SomeException -> Maybe Error
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
err = SomeException -> Maybe SomeException
forall a. a -> Maybe a
Just ((Text -> AwsParty) -> Error -> SomeException
raised Text -> AwsParty
AwsServiceNamed Error
awsErr)
| Just AuthError
authErr <- SomeException -> Maybe AuthError
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
err = SomeException -> Maybe SomeException
forall a. a -> Maybe a
Just (AuthError -> SomeException
authFault AuthError
authErr)
| Bool
otherwise = Maybe SomeException
forall a. Maybe a
Nothing
authFault :: AuthError -> SomeException
authFault :: AuthError -> SomeException
authFault = \case
RetrievalError HttpException
httpErr -> HttpException -> SomeException
raisedHttp HttpException
httpErr
AuthServiceError ServiceError
service -> (Text -> AwsParty) -> Error -> SomeException
raised Text -> AwsParty
AwsServiceNamed (ServiceError -> Error
AWS.ServiceError ServiceError
service)
OtherAuthError SomeException
inner -> SomeException -> Maybe SomeException -> SomeException
forall a. a -> Maybe a -> a
fromMaybe SomeException
inner (SomeException -> Maybe SomeException
awsCallFault SomeException
inner)
MissingEnvError Text
reason -> AwsCredentialFault -> SomeException
forall e. Exception e => e -> SomeException
toException (Text -> AwsCredentialFault
AwsCredentialMissing (Text -> Text
firstLineOf Text
reason))
MissingFileError FilePath
path -> AwsCredentialFault -> SomeException
forall e. Exception e => e -> SomeException
toException (Text -> AwsCredentialFault
AwsCredentialMissing (FilePath -> Text
forall a. ToText a => a -> Text
toText FilePath
path))
InvalidFileError Text
reason -> AwsCredentialFault -> SomeException
forall e. Exception e => e -> SomeException
toException (Text -> AwsCredentialFault
AwsCredentialUnusable (Text -> Text
firstLineOf Text
reason))
InvalidIAMError Text
reason -> AwsCredentialFault -> SomeException
forall e. Exception e => e -> SomeException
toException (Text -> AwsCredentialFault
AwsCredentialUnusable (Text -> Text
firstLineOf Text
reason))
AuthError
CredentialChainExhausted -> AwsCredentialFault -> SomeException
forall e. Exception e => e -> SomeException
toException AwsCredentialFault
AwsCredentialsExhausted
where
firstLineOf :: Text -> Text
firstLineOf = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" (Maybe Text -> Text) -> (Text -> Maybe Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
firstLine
awsCallFault :: SomeException -> Maybe SomeException
awsCallFault :: SomeException -> Maybe SomeException
awsCallFault SomeException
err = SomeException -> Maybe SomeException
amazonkaFault SomeException
err Maybe SomeException -> Maybe SomeException -> Maybe SomeException
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (HttpException -> SomeException
raisedHttp (HttpException -> SomeException)
-> Maybe HttpException -> Maybe SomeException
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SomeException -> Maybe HttpException
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
err)
errorCodeText :: AWS.ErrorCode -> Text
errorCodeText :: ErrorCode -> Text
errorCodeText ErrorCode
code = Text -> Text
T.toLower (ErrorCode
code ErrorCode -> Getting Text ErrorCode Text -> Text
forall s a. s -> Getting a s a -> a
^. Getting Text ErrorCode Text
Iso' ErrorCode Text
AWS._ErrorCode)
raised :: (Text -> AwsParty) -> AWS.Error -> SomeException
raised :: (Text -> AwsParty) -> Error -> SomeException
raised Text -> AwsParty
answering = \case
AWS.TransportError HttpException
httpErr -> HttpException -> SomeException
raisedHttp HttpException
httpErr
AWS.ServiceError ServiceError
service -> AwsRequestFailed -> SomeException
forall e. Exception e => e -> SomeException
toException (AwsParty -> AwsFault -> AwsRequestFailed
AwsRequestFailed (Text -> AwsParty
answering (ServiceError -> Text
serviceName ServiceError
service)) (AwsAnswer -> AwsFault
AwsStatus (ServiceError -> AwsAnswer
serviceAnswer ServiceError
service)))
AWS.SerializeError SerializeError
failure -> AwsRequestFailed -> SomeException
forall e. Exception e => e -> SomeException
toException (AwsParty -> AwsFault -> AwsRequestFailed
AwsRequestFailed (Text -> AwsParty
answering (SerializeError
failure SerializeError -> Getting Text SerializeError Text -> Text
forall s a. s -> Getting a s a -> a
^. (Abbrev -> Const Text Abbrev)
-> SerializeError -> Const Text SerializeError
Lens' SerializeError Abbrev
AWS.serializeError_abbrev ((Abbrev -> Const Text Abbrev)
-> SerializeError -> Const Text SerializeError)
-> ((Text -> Const Text Text) -> Abbrev -> Const Text Abbrev)
-> Getting Text SerializeError Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Const Text Text) -> Abbrev -> Const Text Abbrev
Iso' Abbrev Text
AWS._Abbrev)) (Int -> AwsFault
AwsUndecodable (SerializeError -> Int
undecodableStatus SerializeError
failure)))
raisedHttp :: HTTP.HttpException -> SomeException
raisedHttp :: HttpException -> SomeException
raisedHttp = \case
err :: HttpException
err@(HTTP.HttpExceptionRequest Request
request HttpExceptionContent
_) -> AwsRequestFailed -> SomeException
forall e. Exception e => e -> SomeException
toException (AwsParty -> AwsFault -> AwsRequestFailed
AwsRequestFailed (Text -> Int -> AwsParty
AwsEndpointAt (ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (Request -> ByteString
HTTP.host Request
request)) (Request -> Int
HTTP.port Request
request)) (HttpFault -> AwsFault
AwsHttp (HttpException -> HttpFault
httpFault HttpException
err)))
HttpException
err -> HttpException -> SomeException
forall e. Exception e => e -> SomeException
toException HttpException
err
serviceAnswer :: AWS.ServiceError -> AwsAnswer
serviceAnswer :: ServiceError -> AwsAnswer
serviceAnswer ServiceError
service =
AwsAnswer
{ aaStatus :: Int
aaStatus = Status -> Int
statusCode (ServiceError
service ServiceError -> Getting Status ServiceError Status -> Status
forall s a. s -> Getting a s a -> a
^. Getting Status ServiceError Status
Lens' ServiceError Status
AWS.serviceError_status)
, aaCode :: Text
aaCode = ErrorCode
code ErrorCode -> Getting Text ErrorCode Text -> Text
forall s a. s -> Getting a s a -> a
^. Getting Text ErrorCode Text
Iso' ErrorCode Text
AWS._ErrorCode
, aaRequestId :: Maybe Text
aaRequestId = RequestId -> Text
AWS.fromRequestId (RequestId -> Text) -> Maybe RequestId -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ServiceError
service ServiceError
-> Getting (Maybe RequestId) ServiceError (Maybe RequestId)
-> Maybe RequestId
forall s a. s -> Getting a s a -> a
^. Getting (Maybe RequestId) ServiceError (Maybe RequestId)
Lens' ServiceError (Maybe RequestId)
AWS.serviceError_requestId
, aaMessage :: Maybe Text
aaMessage = if ErrorCode -> Text
errorCodeText ErrorCode
code Text -> [Text] -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` [Text]
signatureCodes then Maybe Text
forall a. Maybe a
Nothing else Text -> Maybe Text
firstLine (Text -> Maybe Text)
-> (ErrorMessage -> Text) -> ErrorMessage -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorMessage -> Text
AWS.fromErrorMessage (ErrorMessage -> Maybe Text) -> Maybe ErrorMessage -> Maybe Text
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ServiceError
service ServiceError
-> Getting (Maybe ErrorMessage) ServiceError (Maybe ErrorMessage)
-> Maybe ErrorMessage
forall s a. s -> Getting a s a -> a
^. Getting (Maybe ErrorMessage) ServiceError (Maybe ErrorMessage)
Lens' ServiceError (Maybe ErrorMessage)
AWS.serviceError_message
}
where
code :: ErrorCode
code = ServiceError
service ServiceError
-> Getting ErrorCode ServiceError ErrorCode -> ErrorCode
forall s a. s -> Getting a s a -> a
^. Getting ErrorCode ServiceError ErrorCode
Lens' ServiceError ErrorCode
AWS.serviceError_code
signatureCodes :: [Text]
signatureCodes :: [Text]
signatureCodes = (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (ErrorCode -> Text
errorCodeText (ErrorCode -> Text) -> (Text -> ErrorCode) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ErrorCode
AWS.newErrorCode) [Text
"InvalidSignatureException", Text
"SignatureDoesNotMatch", Text
"IncompleteSignature"]
firstLine :: Text -> Maybe Text
firstLine :: Text -> Maybe Text
firstLine Text
message = case (Char -> Bool) -> Text -> Text
T.takeWhile (Char -> FilePath -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`notElem` [Char
'\n', Char
'\r']) Text
message of
Text
"" -> Maybe Text
forall a. Maybe a
Nothing
Text
line -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
line
serviceName :: AWS.ServiceError -> Text
serviceName :: ServiceError -> Text
serviceName ServiceError
service = ServiceError
service ServiceError -> Getting Text ServiceError Text -> Text
forall s a. s -> Getting a s a -> a
^. (Abbrev -> Const Text Abbrev)
-> ServiceError -> Const Text ServiceError
Lens' ServiceError Abbrev
AWS.serviceError_abbrev ((Abbrev -> Const Text Abbrev)
-> ServiceError -> Const Text ServiceError)
-> ((Text -> Const Text Text) -> Abbrev -> Const Text Abbrev)
-> Getting Text ServiceError Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Const Text Text) -> Abbrev -> Const Text Abbrev
Iso' Abbrev Text
AWS._Abbrev
renderCredentialFault :: AwsCredentialFault -> Text
renderCredentialFault :: AwsCredentialFault -> Text
renderCredentialFault = \case
AwsCredentialMissing Text
reason -> Text
"AWS credentials missing: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
reason
AwsCredentialUnusable Text
reason -> Text
"AWS credentials unusable: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
reason
AwsCredentialFault
AwsCredentialsExhausted -> Text
"AWS credential discovery found no credentials"
renderRequestFailed :: AwsRequestFailed -> Text
renderRequestFailed :: AwsRequestFailed -> Text
renderRequestFailed AwsRequestFailed
failed = Text
"AWS request failed at " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> AwsRequestFailed -> Text
renderFailure AwsRequestFailed
failed
renderFailure :: AwsRequestFailed -> Text
renderFailure :: AwsRequestFailed -> Text
renderFailure (AwsRequestFailed AwsParty
party AwsFault
fault) = case AwsFault
fault of
AwsStatus AwsAnswer
answer -> Text -> AwsAnswer -> Text
renderAnswer (AwsParty -> Text
renderParty AwsParty
party) AwsAnswer
answer
AwsUndecodable Int
status -> Text -> Int -> Text
renderUndecodable (AwsParty -> Text
renderParty AwsParty
party) Int
status
AwsHttp HttpFault
http -> Text -> HttpFault -> Text
renderHttpFault (AwsParty -> Text
renderParty AwsParty
party) HttpFault
http
renderParty :: AwsParty -> Text
renderParty :: AwsParty -> Text
renderParty = \case
AwsEndpointAt Text
endpointHost Int
endpointPort -> Text -> Int -> Text
hostPortLabel Text
endpointHost Int
endpointPort
AwsServiceNamed Text
service -> Text
service
renderAnswer :: Text -> AwsAnswer -> Text
renderAnswer :: Text -> AwsAnswer -> Text
renderAnswer Text
source AwsAnswer
answer =
Text -> Text
boundedDetail (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$
Text -> HttpFault -> Text
renderHttpFault Text
source (Int -> HttpFault
HttpStatus (AwsAnswer -> Int
aaStatus AwsAnswer
answer))
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> AwsAnswer -> Text
aaCode AwsAnswer
answer)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> (Text -> Text) -> Maybe Text -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" (\Text
requestId -> Text
" (request " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
requestId Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
")") (AwsAnswer -> Maybe Text
aaRequestId AwsAnswer
answer)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> (Text -> Text) -> Maybe Text -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" (Text
": " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (AwsAnswer -> Maybe Text
aaMessage AwsAnswer
answer)
renderUndecodable :: Text -> Int -> Text
renderUndecodable :: Text -> Int -> Text
renderUndecodable Text
source Int
status = Text -> HttpFault -> Text
renderHttpFault Text
source (Int -> HttpFault
HttpStatus Int
status) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
", an answer that could not be decoded"
undecodableStatus :: AWS.SerializeError -> Int
undecodableStatus :: SerializeError -> Int
undecodableStatus SerializeError
failure = Status -> Int
statusCode (SerializeError
failure SerializeError -> Getting Status SerializeError Status -> Status
forall s a. s -> Getting a s a -> a
^. Getting Status SerializeError Status
Lens' SerializeError Status
AWS.serializeError_status)
requestEndpoint :: (AWS.AWSRequest a) => AWS.Env -> a -> AwsParty
requestEndpoint :: forall a. AWSRequest a => Env -> a -> AwsParty
requestEndpoint Env
env a
request = Text -> Int -> AwsParty
AwsEndpointAt (ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (Endpoint
endpoint Endpoint -> Getting ByteString Endpoint ByteString -> ByteString
forall s a. s -> Getting a s a -> a
^. Getting ByteString Endpoint ByteString
Lens' Endpoint ByteString
AWS.endpoint_host)) (Endpoint
endpoint Endpoint -> Getting Int Endpoint Int -> Int
forall s a. s -> Getting a s a -> a
^. Getting Int Endpoint Int
Lens' Endpoint Int
AWS.endpoint_port)
where
service :: Service
service = (Service -> Service) -> a -> Request a
forall a. AWSRequest a => (Service -> Service) -> a -> Request a
AWS.request (Env -> Service -> Service
forall (withAuth :: * -> *). Env' withAuth -> Service -> Service
AWS.overrides Env
env) a
request Request a -> Getting Service (Request a) Service -> Service
forall s a. s -> Getting a s a -> a
^. Getting Service (Request a) Service
forall a (f :: * -> *).
Functor f =>
(Service -> f Service) -> Request a -> f (Request a)
AWS.request_service
endpoint :: Endpoint
endpoint = (Service
service Service
-> Getting (Region -> Endpoint) Service (Region -> Endpoint)
-> Region
-> Endpoint
forall s a. s -> Getting a s a -> a
^. Getting (Region -> Endpoint) Service (Region -> Endpoint)
Lens' Service (Region -> Endpoint)
AWS.service_endpoint) (Env -> Region
forall (withAuth :: * -> *). Env' withAuth -> Region
AWS.region Env
env)