Skip to content

Commit

Permalink
handle specific windows network exceptions in Jörmungandr http client
Browse files Browse the repository at this point in the history
Seems like the servant-client does not handle IO / Network exceptions
that can occur on Windows correctly. So this is a first work-around
that. We may want to move this logic to our Jörmungandr http-client
itself to actually properly handle this type of failure on every
endpoint.
  • Loading branch information
KtorZ committed Nov 13, 2019
1 parent 27ccd66 commit aa81f70
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/jormungandr/src/Cardano/Wallet/Jormungandr/Api/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import Cardano.Wallet.Primitive.Types
import Control.Arrow
( left )
import Control.Exception
( Exception )
( Exception, SomeException, handle, throwIO )
import Control.Monad
( void )
import Control.Monad.Catch
Expand All @@ -87,6 +87,8 @@ import Control.Monad.Trans.Except
( ExceptT (..), throwE, withExceptT )
import Data.Coerce
( coerce )
import Data.List
( isSubsequenceOf )
import Data.Maybe
( mapMaybe )
import Data.Proxy
Expand Down Expand Up @@ -252,7 +254,24 @@ mkJormungandrClient mgr baseUrl = JormungandrClient
}
where
run :: ClientM a -> IO (Either ServantError a)
run query = runClientM query (mkClientEnv mgr baseUrl)
run query = handle hWindowsNetworkError $
runClientM query (mkClientEnv mgr baseUrl)
where
windowsNetworkError :: [String]
windowsNetworkError =
[ "WSAECONNREFUSED" -- Connection refused
, "WSAEADDRNOTAVAIL" -- Cannot assign requested address
, "WSAETIMEDOUT" -- Connection timed out
, "WSAEHOSTUNREACH" -- Host is unreachable
, "WSAEHOSTDOWN" -- Host is down
]

hWindowsNetworkError :: SomeException -> IO (Either ServantError a)
hWindowsNetworkError e
| any (`isSubsequenceOf` show e) windowsNetworkError =
pure $ Left $ ConnectionError $ T.pack $ show e
| otherwise =
throwIO e

defaultHandler
:: Link
Expand Down

0 comments on commit aa81f70

Please sign in to comment.