module Page ( getPage ) where import Control.Exception (SomeException, try) import qualified Data.Text as T import Network.HTTP (simpleHTTP, getRequest, getResponseBody) import Model.URL getPage :: URL -> IO (Either T.Text T.Text) getPage url = mapLeft (T.pack . show) <$> (try (unsafeGetPage url) :: IO (Either SomeException T.Text)) unsafeGetPage :: URL -> IO T.Text unsafeGetPage url = simpleHTTP (getRequest url) >>= (\x -> T.pack <$> getResponseBody x) mapLeft :: (a -> c) -> Either a b -> Either c b mapLeft f (Left l) = Left (f l) mapLeft _ (Right r) = (Right r)