Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jormungandr: Fix "Blockchain tip not set in REST context" #1681

Merged
merged 1 commit into from
May 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/jormungandr/src/Cardano/Wallet/Jormungandr/Api/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ import GHC.Generics
import Network.HTTP.Client
( Manager, defaultManagerSettings, newManager )
import Network.HTTP.Types.Status
( status400, status404, status503 )
( status400, status404, status500, status503 )
import Servant.API
( (:<|>) (..) )
import Servant.Client
Expand Down Expand Up @@ -178,8 +178,16 @@ mkJormungandrClient mgr baseUrl = JormungandrClient
<$> defaultHandler ctx x

, getTipId = ExceptT $ do
let ctx = safeLink api (Proxy @GetTipId)
run (getBlockId <$> cGetTipId) >>= defaultHandler ctx
run (getBlockId <$> cGetTipId) >>= \case
Left (FailureResponse _ e) | responseStatusCode e == status500 ->
-- NOTE: /api/v0/tip returns 500 Internal Server Error when
-- called during bootstrap. Treat this status the same as 503
-- Service Unavailable, so that getTipId can be polled until
-- jormungandr is ready.
return $ Left $ ErrNetworkUnreachable $ T.pack $ show e
x -> do
let ctx = safeLink api (Proxy @GetTipId)
defaultHandler ctx x

, getBlock = \blockId -> ExceptT $ do
let action = cGetBlock (BlockId blockId)
Expand Down