egonSchiele / HandsomeSoup

Easy HTML parsing for Haskell
http://egonschiele.github.com/HandsomeSoup
BSD 3-Clause "New" or "Revised" License
124 stars 20 forks source link

Error: Main.hs: <socket: 9>: hGetBufSome: timeout (Connection timed out) #15

Open djg123 opened 10 years ago

djg123 commented 10 years ago

I got the following error after calling fromUrl: Main.hs: <socket: 9>: hGetBufSome: timeout (Connection timed out), and then my program died.

This error makes sense, but is it documented? I would like a way to handle it within my code instead of my program dying.

egonSchiele commented 10 years ago

Ugh. fromUrl just uses HXT's readDocument function (link), which in turn uses the HTTP package, which in this case just dies on an error. You can switch to using a combination of openUrl and parseHtml instead, something like:

contents <- runMaybeT $ openUrl "http://foo.com"
case contents of
  Nothing -> ...
  Just val -> parseHtml val

Long term I should probably switch the implementation of fromUrl to something like this too.