PandocMonad: Let fetching fail if the HTTP request is not successful.

HTTP requests that don't return a 200 error code are now treated as an
error. This ensures that a warning is triggered when using
`--embed-resources` or `--extract-media`.
This commit is contained in:
Albert Krewinkel
2025-09-09 10:51:04 +02:00
committed by John MacFarlane
parent 47e1cc46c6
commit 4b126bd90b
+3 -3
View File
@@ -46,7 +46,7 @@ import qualified Network.TLS as TLS
import qualified Network.TLS.Extra as TLS
import Network.HTTP.Client
(httpLbs, Manager, responseBody, responseHeaders,
Request(port, host, requestHeaders), parseRequest, newManager)
Request(port, host, requestHeaders), parseUrlThrow, newManager)
import Network.HTTP.Client.Internal (addProxy)
import Network.HTTP.Client.TLS (mkManagerSettings)
import Network.HTTP.Types.Header ( hContentType )
@@ -168,9 +168,9 @@ openURL u
proxy <- tryIOError (getEnv "http_proxy")
let addProxy' x = case proxy of
Left _ -> return x
Right pr -> parseRequest pr >>= \r ->
Right pr -> parseUrlThrow pr >>= \r ->
return (addProxy (host r) (port r) x)
req <- parseRequest (unpack u) >>= addProxy'
req <- parseUrlThrow (unpack u) >>= addProxy'
let req' = req{requestHeaders = customHeaders ++ requestHeaders req}
resp <- httpLbs req' manager
return (B.concat $ toChunks $ responseBody resp,