This is one of the
haddock code from http-conduit (I have changed slightly to include one import):
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Conduit
import Network
import Data.Time.Clock
import Data.Time.Calendar
import qualified Control.Exception as E
import Network.HTTP.Types.Status (statusCode)
past :: UTCTime
past = UTCTime (ModifiedJulianDay 56200) (secondsToDiffTime 0)
future :: UTCTime
future = UTCTime (ModifiedJulianDay 562000) (secondsToDiffTime 0)
cookie :: Cookie
cookie = Cookie { cookie_name = "password_hash"
, cookie_value = "abf472c35f8297fbcabf2911230001234fd2"
, cookie_expiry_time = future
, cookie_domain = "
example.com"
, cookie_path = "/"
, cookie_creation_time = past
, cookie_last_access_time = past
, cookie_persistent = False
, cookie_host_only = False
, cookie_secure_only = False
, cookie_http_only = False
}
main = withSocketsDo $ do
request' <- parseUrl "
http://example.com/secret-page"
let request = request' { cookieJar = Just $ createCookieJar [cookie] }
E.catch (withManager $ httpLbs request)
(\(StatusCodeException s _ _) ->
if statusCode s==403 then putStrLn "login failed" else return ())
It produces the following compile error:
Expected type: IO (Response Data.ByteString.Lazy.Internal.ByteString)
Actual type: IO ()
On inspecting further, it becomes obvious that (withManager $ httpLbs request) has type of `IO (Response ByteString)
whereas (\(StatusCodeException s _ _) -> if statusCode s==403 then putStrLn "login failed" else return ()) has a type of
IO (). E.catch constrains them to have a single type. Any approaches to solve this problem ?
Regards,
Sibi