A peer-to-peer stack for code collaboration
Add IPFS API path to timeout errors
Thomas Scholtesf9f9faf4aa67
diff --git a/src/Radicle/Daemon/Monad.hs b/src/Radicle/Daemon/Monad.hsindex adc0fbc..a86978f 100644--- a/src/Radicle/Daemon/Monad.hs+++ b/src/Radicle/Daemon/Monad.hs@@ -79,6 +79,6 @@ displayError = \caseIpfsException msg -> ("There was an error using the IPFS daemon", [("ipfs-error", msg)])IpfsExceptionErrResp msg -> ("The IPFS daemon returned an error", [("ipfs-error", msg)])IpfsExceptionErrRespNoMsg -> ("There was an unknown error using IPFS", [])- IpfsExceptionTimeout -> ("Timeout communicating with IPFS daemon", [])+ IpfsExceptionTimeout apiPath -> ("Timeout communicating with IPFS daemon", [("api-path", apiPath)])IpfsExceptionInvalidResponse url parseError -> ("Cannot parse IPFS daemon response", [("url", url), ("parse-error", parseError)])IpfsExceptionNoDaemon -> ("Cannot connect to the IPFS daemon", [])diff --git a/src/Radicle/Ipfs.hs b/src/Radicle/Ipfs.hsindex 3a18ee2..44afce6 100644--- a/src/Radicle/Ipfs.hs+++ b/src/Radicle/Ipfs.hs@@ -58,8 +58,9 @@ data IpfsException= IpfsException Text| IpfsExceptionErrResp Text| IpfsExceptionErrRespNoMsg- -- | The request to the IPFS daemon timed out.- | IpfsExceptionTimeout+ -- | The request to the IPFS daemon timed out. The constructor+ -- parameter is the API path.+ | IpfsExceptionTimeout Text-- | JSON response from the IPFS Api cannot be parsed. First-- argument is the request path, second argument the JSON parsing-- error@@ -73,15 +74,17 @@ instance Exception IpfsException whereIpfsException msg -> toS msgIpfsExceptionNoDaemon -> "Cannot connect to " <> nameIpfsExceptionInvalidResponse url _ -> "Cannot parse " <> name <> " response for " <> toS url- IpfsExceptionTimeout -> name <> " took too long to respond"+ IpfsExceptionTimeout apiPath -> name <> " took too long to respond for " <> toS apiPathIpfsExceptionErrResp msg -> toS msgIpfsExceptionErrRespNoMsg -> name <> " failed with no error message"wherename = "Radicle IPFS daemon"-- | Catches 'HttpException's and re-throws them as 'IpfsException's.-mapHttpException :: forall a. IO a -> IO a-mapHttpException io = catch io (throw . mapHttpExceptionData)+--+-- @path@ is the IPFS API path that is added to some errors.+mapHttpException :: Text -> IO a -> IO a+mapHttpException path io = catch io (throw . mapHttpExceptionData)wheremapHttpExceptionData :: HttpException -> IpfsExceptionmapHttpExceptionData = \case@@ -94,7 +97,7 @@ mapHttpException io = catch io (throw . mapHttpExceptionData)(Aeson.decodeStrict ->Just (Aeson.Object (HashMap.lookup "Message" ->Just (Aeson.String msg))))) -> (IpfsExceptionErrResp msg)- Http.ResponseTimeout -> IpfsExceptionTimeout+ Http.ResponseTimeout -> IpfsExceptionTimeout pathConnectionFailure _ -> IpfsExceptionNoDaemon_ -> IpfsExceptionErrRespNoMsg@@ -283,7 +286,7 @@ ipfsHttpGet=> Text -- ^ Path of the endpoint under "/api/v0/"-> [(Text, Text)] -- ^ URL query parameters-> IO a-ipfsHttpGet path params = mapHttpException $ do+ipfsHttpGet path params = mapHttpException path $ dolet opts = Wreq.defaults & Wreq.params .~ paramsurl <- ipfsApiUrl pathres <- Wreq.getWith opts (toS url)@@ -296,7 +299,7 @@ ipfsHttpPost-> Text -- ^ Name of the argument for payload-> LByteString -- ^ Payload argument-> IO a-ipfsHttpPost path params payloadArgName payload = mapHttpException $ do+ipfsHttpPost path params payloadArgName payload = mapHttpException path $ dores <- ipfsHttpPost' path params payloadArgName payloadgetJsonResponseBody path res@@ -306,7 +309,7 @@ ipfsHttpPost'-> Text -- ^ Name of the argument for payload-> LByteString -- ^ Payload argument-> IO (Wreq.Response LByteString)-ipfsHttpPost' path params payloadArgName payload = mapHttpException $ do+ipfsHttpPost' path params payloadArgName payload = mapHttpException path $ dolet opts = Wreq.defaults & Wreq.params .~ paramsurl <- ipfsApiUrl pathWreq.postWith opts (toS url) (Wreq.partLBS payloadArgName payload)