Skip to content

Commit

Permalink
Improve error message for proxy connection failures
Browse files Browse the repository at this point in the history
  • Loading branch information
hsenag committed Apr 30, 2024
1 parent 1701cc6 commit 9901538
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Network/HTTP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import Network.HTTP.Base
import qualified Network.HTTP.HandleStream as S
-- old implementation: import Network.HTTP.Stream
import Network.TCP
import Network.Stream ( Result )
import Network.Stream ( Result, ConnError(ErrorProxyConnection) )
import Network.URI ( parseURI )

import Data.Maybe ( fromMaybe )
Expand Down
1 change: 1 addition & 0 deletions Network/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ data ConnError
| ErrorClosed
| ErrorParse String
| ErrorMisc String
| ErrorProxyConnection String -- Added ErrorProxyConnection variant for proxy connection errors
deriving(Show,Eq)

-- in GHC 7.0 the Monad instance for Error no longer
Expand Down
5 changes: 3 additions & 2 deletions Network/StreamSocket.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Network.StreamSocket
) where

import Network.Stream
( Stream(..), ConnError(ErrorReset, ErrorMisc), Result
( Stream(..), ConnError(ErrorReset, ErrorMisc, ErrorProxyConnection), Result
)
import Network.Socket
( Socket, getSocketOption, shutdown
Expand All @@ -49,6 +49,8 @@ handleSocketError sk e =
case se of
0 -> ioError e
10054 -> return $ Left ErrorReset -- reset
-- Enhanced error handling for proxy connection issues
10061 -> return $ Left $ ErrorProxyConnection "Proxy connection failed"
_ -> return $ Left $ ErrorMisc $ show se

myrecv :: Socket -> Int -> IO String
Expand Down Expand Up @@ -94,4 +96,3 @@ writeBlockSocket sk str = (liftM Right $ fn str) `catchIO` (handleSocketError sk
where
fn [] = return ()
fn x = send sk (toUTF8BS x) >>= \i -> fn (drop i x)

0 comments on commit 9901538

Please sign in to comment.