summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-05-07 13:11:04 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-05-07 13:11:04 +0200
commit99be906101f7852e84e5da9c3b66dd6d99f649da (patch)
treee9ae7e7d5a97e20d04c0a2957295a0e2eb8051bb /src/Text/Pandoc/Shared.hs
parentd414b2543a1686007e84c54bc711dff969dfb569 (diff)
Added PandocHttpException, trap exceptions in fetching from URLs.
Closes #3646.
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r--src/Text/Pandoc/Shared.hs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 44a26509b..0ebaf0f89 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -141,7 +141,8 @@ import Text.Pandoc.Data (dataFiles)
import Paths_pandoc (getDataFileName)
#endif
import Network.HTTP.Client (httpLbs, responseBody, responseHeaders,
- Request(port,host,requestHeaders))
+ Request(port,host,requestHeaders),
+ HttpException)
import Network.HTTP.Client (parseRequest)
import Network.HTTP.Client (newManager)
import Network.HTTP.Client.Internal (addProxy)
@@ -702,13 +703,13 @@ readDataFileUTF8 userDir fname =
UTF8.toString `fmap` readDataFile userDir fname
-- | Read from a URL and return raw data and maybe mime type.
-openURL :: String -> IO (BS.ByteString, Maybe MimeType)
+openURL :: String -> IO (Either HttpException (BS.ByteString, Maybe MimeType))
openURL u
| Just u'' <- stripPrefix "data:" u =
let mime = takeWhile (/=',') u''
contents = B8.pack $ unEscapeString $ drop 1 $ dropWhile (/=',') u''
- in return (decodeLenient contents, Just mime)
- | otherwise = withSocketsDo $ do
+ in return $ Right (decodeLenient contents, Just mime)
+ | otherwise = E.try $ withSocketsDo $ do
let parseReq = parseRequest
(proxy :: Either IOError String) <-
tryIOError $ getEnv "http_proxy"