diff --git a/connexpay/src/Web/Connexpay/Payments.hs b/connexpay/src/Web/Connexpay/Payments.hs index 2c9dee6..ade9b85 100644 --- a/connexpay/src/Web/Connexpay/Payments.hs +++ b/connexpay/src/Web/Connexpay/Payments.hs @@ -77,7 +77,6 @@ sendRequest' resp endpoint body = r <- if tls then reqCb POST (url https) jbody resp auth (logRequest obj) else reqCb POST (url http) jbody resp auth (logRequest obj) - logResponse r pure r where addGuid b = diff --git a/connexpay/src/Web/Connexpay/Types.hs b/connexpay/src/Web/Connexpay/Types.hs index 6564901..9226278 100644 --- a/connexpay/src/Web/Connexpay/Types.hs +++ b/connexpay/src/Web/Connexpay/Types.hs @@ -10,10 +10,11 @@ import Control.Monad.Except (MonadError, ExceptT, runExceptT, throwError) import Control.Monad.IO.Class import Control.Monad.Reader import Data.Aeson +import Data.ByteString (ByteString) import Data.Text (Text) import Data.Text qualified as Text import Data.UUID (UUID) -import Network.HTTP.Client hiding (responseHeaders) +import Network.HTTP.Client as Client import Network.HTTP.Req import Network.HTTP.Types @@ -45,8 +46,14 @@ instance MonadHttp ConnexpayM where , Just f <- guessFailure (statusCode $ responseStatus resp) err.message = throwError (PaymentFailure f) handleHttpException (VanillaHttpException (HttpExceptionRequest _ c)) = throwError (ConnectionError $ HttpFailure c) - getHttpConfig = do mgr <- asks (.manager) - pure (defaultHttpConfig { httpConfigAltManager = Just mgr }) + getHttpConfig = + do mgr <- asks (.manager) + log_ <- asks (.logAction) + let cfg = + defaultHttpConfig + { httpConfigAltManager = Just mgr + , httpConfigLogResponse = logResponse log_ } + pure cfg runConnexpay :: Connexpay -> ConnexpayM a -> IO (Either ConnexpayError a) @@ -62,11 +69,10 @@ bearerToken :: ConnexpayM (Maybe BearerToken) bearerToken = do v <- asks (.bearerToken) liftIO (readMVar v) -logResponse :: HttpResponse r => r -> ConnexpayM () -logResponse r = - do log_ <- asks (.logAction) - liftIO (log_ msg) +logResponse :: (Text -> IO ()) -> Request -> Response a -> ByteString -> IO () +logResponse log_ _req resp body = log_ msg where msg = Text.unlines [ "Connexpay response:" - , "HTTP code: " <> tshow (responseCode r) - , "Headers: " <> tshow (responseHeaders r) + , "HTTP code: " <> tshow (statusCode (responseStatus resp)) + , "Headers: " <> tshow (Client.responseHeaders resp) + , "Body: " <> tshow body ] diff --git a/connexpay/src/Web/Connexpay/Utils.hs b/connexpay/src/Web/Connexpay/Utils.hs index 7f3ab77..c625719 100644 --- a/connexpay/src/Web/Connexpay/Utils.hs +++ b/connexpay/src/Web/Connexpay/Utils.hs @@ -17,8 +17,8 @@ whenJust Nothing _ = pure () tshow :: Show a => a -> Text tshow = Text.pack . show -responseHeaders :: HttpResponse response => response -> [Header] -responseHeaders = Client.responseHeaders . toVanillaResponse +--responseHeaders :: HttpResponse response => response -> [Header] +--responseHeaders = Client.responseHeaders . toVanillaResponse responseCode :: HttpResponse response => response -> Int responseCode = statusCode . Client.responseStatus . toVanillaResponse diff --git a/stack.yaml b/stack.yaml index f541a13..b4ff741 100644 --- a/stack.yaml +++ b/stack.yaml @@ -7,7 +7,8 @@ packages: extra-deps: - git: https://github.com/typeable/bucks.git commit: 9e378b675fe7fb88d5ddb3af068d82eb441f343c - + - git: https://github.com/typeable/req.git + commit: 8829ac5197f7a4b3f04b7fdfc3ea66cfe70ab0a5 nix: packages: [zlib] local-bin-path: bin