Skip to content

Commit

Permalink
log: better error for P2P session failure
Browse files Browse the repository at this point in the history
Change-Id: Ife41e08c80c5b9fe1ac43f9c97377eb8f5a1047c
  • Loading branch information
edmundnoble committed May 27, 2024
1 parent aeef468 commit a85b118
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Unreleased (2024-XX-YY)

Changes:

- Improve log message for failed P2P session (#xxxx)

Internal Changes:

Expand Down
9 changes: 8 additions & 1 deletion src/P2P/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ViewPatterns #-}

-- |
-- Module: P2P.Node
Expand Down Expand Up @@ -98,6 +99,7 @@ import GHC.Generics
import GHC.Stack

import qualified Network.HTTP.Client as HTTP
import qualified Network.HTTP.Types as HTTP

import Numeric.Natural

Expand Down Expand Up @@ -649,7 +651,7 @@ awaitSessions node = do
Right Nothing -> P2pSessionTimeout <$ countTimeout node
Right (Just True) -> P2pSessionResultSuccess <$ countSuccess node
Right (Just False) -> P2pSessionResultFailure <$ countFailure node
Left e -> P2pSessionException (sshow e) <$ countException node
Left e -> P2pSessionException (showClientError e) <$ countException node
return (p, i, a, result)

-- update peer db entry
Expand Down Expand Up @@ -699,6 +701,11 @@ awaitSessions node = do
$ loggFun node Info $ JsonLog stats

where
showClientError e
| Just (FailureResponse _ resp) <- fromException e =
"Error code " <> sshow (HTTP.statusCode $ responseStatusCode resp)
| otherwise =
sshow e
peerDb = _p2pNodePeerDb node

waitAnySession
Expand Down

0 comments on commit a85b118

Please sign in to comment.