module Utils.HTTP ( get ) where import Control.Exception (SomeException, try) import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as BS import Data.Text (Text) import qualified Data.Text as T import Network.HTTP.Conduit import Model.URL import Utils.Either (mapLeft) get :: (ByteString -> Text) -> URL -> IO (Either Text Text) get decode url = mapLeft (T.pack . show) <$> (try (unsafeGetPage decode url) :: IO (Either SomeException Text)) unsafeGetPage :: (ByteString -> Text) -> URL -> IO Text unsafeGetPage decode url = (decode . BS.toStrict) <$> simpleHttp (T.unpack url)