better unpack these ByteStrings

This commit is contained in:
nek0 2015-10-19 01:59:18 +02:00
parent 3eaa3c19e7
commit 19f97dd4dc

View file

@ -11,6 +11,7 @@ import Control.Exception
import qualified Data.Text as T import qualified Data.Text as T
import Data.Text.Encoding (decodeUtf8) import Data.Text.Encoding (decodeUtf8)
import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Aeson as A import Data.Aeson as A
import Data.Time.Clock import Data.Time.Clock
import Data.Yaml as Y import Data.Yaml as Y
@ -79,9 +80,9 @@ main = do
liftIO $ putStrLn $ (show u) ++ "\n" liftIO $ putStrLn $ (show u) ++ "\n"
resp <- indexDocument (IndexName "user") (MappingName "user") defaultIndexDocumentSettings u dId resp <- indexDocument (IndexName "user") (MappingName "user") defaultIndexDocumentSettings u dId
case statusCode (responseStatus resp) of case statusCode (responseStatus resp) of
200 -> liftIO $ putStrLn $ "OK: " ++ (show $ responseBody resp) 200 -> liftIO $ putStrLn $ "OK: " ++ (BL.unpack $ responseBody resp)
201 -> liftIO $ putStrLn $ "OK: " ++ (show $ responseBody resp) 201 -> liftIO $ putStrLn $ "OK: " ++ (BL.unpack $ responseBody resp)
_ -> liftIO $ putStrLn $ "!!Failure!!: " ++ (show $ responseBody resp) _ -> liftIO $ putStrLn $ "!!Failure!!: " ++ (BL.unpack $ responseBody resp)
bla -> bla ->
error $ "malformed entry" ++ show bla error $ "malformed entry" ++ show bla
) userRows ) userRows
@ -93,9 +94,9 @@ main = do
liftIO $ putStrLn $ (show a) ++ "\n" liftIO $ putStrLn $ (show a) ++ "\n"
resp <- indexDocument (IndexName "album") (MappingName "album") defaultIndexDocumentSettings a dId resp <- indexDocument (IndexName "album") (MappingName "album") defaultIndexDocumentSettings a dId
case statusCode (responseStatus resp) of case statusCode (responseStatus resp) of
200 -> liftIO $ putStrLn $ "OK: " ++ (show $ responseBody resp) 200 -> liftIO $ putStrLn $ "OK: " ++ (BL.unpack $ responseBody resp)
201 -> liftIO $ putStrLn $ "OK: " ++ (show $ responseBody resp) 201 -> liftIO $ putStrLn $ "OK: " ++ (BL.unpack $ responseBody resp)
_ -> liftIO $ putStrLn $ "!!Failure!!: " ++ (show $ responseBody resp) _ -> liftIO $ putStrLn $ "!!Failure!!: " ++ (BL.unpack $ responseBody resp)
bla -> bla ->
error $ "malformed entry: " ++ show bla error $ "malformed entry: " ++ show bla
) albumRows ) albumRows
@ -107,9 +108,9 @@ main = do
liftIO $ putStrLn $ (show m) ++ "\n" liftIO $ putStrLn $ (show m) ++ "\n"
resp <- indexDocument (IndexName "medium") (MappingName "medium") defaultIndexDocumentSettings m dId resp <- indexDocument (IndexName "medium") (MappingName "medium") defaultIndexDocumentSettings m dId
case statusCode (responseStatus resp) of case statusCode (responseStatus resp) of
200 -> liftIO $ putStrLn $ "OK: " ++ (show $ responseBody resp) 200 -> liftIO $ putStrLn $ "OK: " ++ (BL.unpack $ responseBody resp)
201 -> liftIO $ putStrLn $ "OK: " ++ (show $ responseBody resp) 201 -> liftIO $ putStrLn $ "OK: " ++ (BL.unpack $ responseBody resp)
_ -> liftIO $ putStrLn $ "!!Failure!!: " ++ (show $ responseBody resp) _ -> liftIO $ putStrLn $ "!!Failure!!: " ++ (BL.unpack $ responseBody resp)
bla -> bla ->
error $ "malformed entry" ++ show bla error $ "malformed entry" ++ show bla
) mediumRows ) mediumRows
@ -121,9 +122,9 @@ main = do
liftIO $ putStrLn $ (show c) ++ "\n" liftIO $ putStrLn $ (show c) ++ "\n"
resp <- indexDocument (IndexName "medium") (MappingName "medium") defaultIndexDocumentSettings c dId resp <- indexDocument (IndexName "medium") (MappingName "medium") defaultIndexDocumentSettings c dId
case statusCode (responseStatus resp) of case statusCode (responseStatus resp) of
200 -> liftIO $ putStrLn $ "OK: " ++ (show $ responseBody resp) 200 -> liftIO $ putStrLn $ "OK: " ++ (BL.unpack $ responseBody resp)
201 -> liftIO $ putStrLn $ "OK: " ++ (show $ responseBody resp) 201 -> liftIO $ putStrLn $ "OK: " ++ (BL.unpack $ responseBody resp)
_ -> liftIO $ putStrLn $ "!!Failure!!: " ++ (show $ responseBody resp) _ -> liftIO $ putStrLn $ "!!Failure!!: " ++ (BL.unpack $ responseBody resp)
bla -> bla ->
error $ "malformed entry" ++ show bla error $ "malformed entry" ++ show bla
) commentRows ) commentRows