speechmatics 0.7.1.0 → 0.7.2.0
raw patch · 2 files changed
+21/−8 lines, 2 filesdep +split
Dependencies added: split
Files
- speechmatics.cabal +3/−2
- src/Speechmatics/Request.hs +18/−6
speechmatics.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: bb5a8fd3e472f8d525b9a3ea29afda678c16f8324dfecd227ed234ac777821d8+-- hash: 72cc809bd43f4f4c0533e2db299a68b2c0ba8614bf8b9391b9a614715fcea2c6 name: speechmatics-version: 0.7.1.0+version: 0.7.2.0 synopsis: Speechmatics api client description: Upload audio files to speechmatics to get a transcription category: API@@ -39,6 +39,7 @@ , mime-types , monad-control , mtl+ , split , text , text-format-heavy , wreq
src/Speechmatics/Request.hs view
@@ -18,7 +18,7 @@ import Network.HTTP.Client (defaultManagerSettings, managerResponseTimeout, responseTimeoutMicro,- HttpException)+ HttpException(..)) import Data.Bifunctor import Network.HTTP.Client.OpenSSL@@ -33,7 +33,7 @@ import qualified Data.ByteString.Lazy.Char8 as C8LBS import Data.Maybe import Data.Monoid-import Data.Text+import qualified Data.Text as Text import qualified Data.Text.Lazy as Lazy import qualified Network.Wreq.Session as Sess import qualified Network.Wreq.Types as Types@@ -45,6 +45,8 @@ import qualified Speechmatics.Log as Log import qualified Data.ByteString as BS import Control.Monad.Trans.Control(liftWith)+import Data.Foldable(traverse_)+import Data.List.Split class AsHttpExceptiont t where _HttpException :: Prism' t HttpException@@ -58,19 +60,29 @@ liftWith (\run -> catching _HttpException func - (\x -> - (run $ Log.error $ pack ("Got an http exception: " <> show x)) >>+ (\x -> do+ let handled = handleException x+ (traverse_ (run . Log.error . Text.pack) (["Got an http exception: "] <> handled)) >> throwIO x ) ) +-- | heavy logger doesn't like '{'+format :: Char -> Char+format '{' = '<'+format '}' = '>'+format x = x +handleException :: HttpException -> [String]+handleException (HttpExceptionRequest request content) = ["Failed to make request:"] <> lines (fmap format (show request)) <> [" With content:"] <> chunksOf 120 (fmap format (show content))+handleException x = lines (show x)+ getWith :: Wreq.Options -> Sess.Session -> String -> LoggingT IO (Wreq.Response C8LBS.ByteString) getWith opts sess str = do- Log.debug (pack ("Making get request to " <> str))+ Log.debug (Text.pack ("Making get request to " <> str)) logException $ Sess.getWith opts sess str postWith :: Types.Postable a => Wreq.Options -> Sess.Session -> String -> a -> LoggingT IO (Wreq.Response C8LBS.ByteString) postWith opts sess str post = do- Log.debug (pack ("Making get request to " <> str))+ Log.debug (Text.pack ("Making get request to " <> str)) logException $ Sess.postWith opts sess str post