Commits

Colin Woodbury  committed d5cf37b Merge

Merge pull request #193 from dkasak/master

Handle HTTP exceptions when fetching data.

  • Participants
  • Parent commits 9b2f889, 45652a2

Comments (0)

Files changed (1)

 
 import qualified Data.ByteString.Lazy as L
 
-import Data.ByteString.Lazy.Char8 (unpack)
+import Data.ByteString.Lazy.Char8 (pack, unpack)
+import Control.Exception    (catch)
 import System.FilePath      (splitFileName, (</>))
 import Network.HTTP         (urlEncodeVars)
 import System.IO            (hClose, openFile, IOMode(WriteMode))
 urlContents url = do
   req <- parseUrl url
   let req2 = req { responseTimeout = Nothing}
-  responseBody `fmap` withManager (httpLbs req2)
+  catch (fmap responseBody . withManager . httpLbs $ req2) handleException
+
+handleException :: HttpException -> IO L.ByteString
+handleException _ = return (pack "")
 
 saveUrlContents :: FilePath -> String -> IO FilePath
 saveUrlContents fpath url = do