From 4ddd6d1f6df2bab75d42b6d45b816e92e7173529 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sat, 11 Apr 2015 19:20:04 +0200 Subject: Fixing parsing errors, and use Text from now --- src/Page.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/Page.hs') diff --git a/src/Page.hs b/src/Page.hs index b70db70..b048410 100644 --- a/src/Page.hs +++ b/src/Page.hs @@ -4,11 +4,18 @@ module Page import Control.Exception (SomeException, try) +import qualified Data.Text as T + import Network.HTTP (simpleHTTP, getRequest, getResponseBody) -getPage :: String -> IO (Either String String) +import Model.URL + +getPage :: URL -> IO (Either T.Text T.Text) getPage url = - mapLeft show <$> (try (simpleHTTP (getRequest url) >>= getResponseBody) :: IO (Either SomeException String)) + 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) -- cgit v1.2.3