module Page ( getPage ) where import Control.Exception (SomeException, try) import Data.Text (Text) import qualified Data.Text as T import Network.HTTP (simpleHTTP, getRequest, getResponseBody) import Model.URL import Utils.Either (mapLeft) getPage :: URL -> IO (Either Text Text) getPage url = mapLeft (T.pack . show) <$> (try (unsafeGetPage url) :: IO (Either SomeException Text)) unsafeGetPage :: URL -> IO Text unsafeGetPage url = simpleHTTP (getRequest (T.unpack url)) >>= (\x -> T.pack <$> getResponseBody x)