From 8f8ffd0e6676cd3894c806133fb56908d6885719 Mon Sep 17 00:00:00 2001 From: Wietse Wind Date: Sun, 8 Oct 2023 21:26:49 +0200 Subject: [PATCH] Fix error handling/missing obj timing --- index.mjs | 1 + lib/events/ledgerReady.mjs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/index.mjs b/index.mjs index 0be9710..bb4aac5 100644 --- a/index.mjs +++ b/index.mjs @@ -52,6 +52,7 @@ connections c.on('online', () => subscribe()) + c.on('error', e => console.error(e?.message || e)) }) // Play nice with Docker etc. diff --git a/lib/events/ledgerReady.mjs b/lib/events/ledgerReady.mjs index fa30646..2d9a295 100644 --- a/lib/events/ledgerReady.mjs +++ b/lib/events/ledgerReady.mjs @@ -76,7 +76,11 @@ const ledgerReady = async (ledger, readyElement) => { } const waitForLedgerReady = ledgerIndex => { - return ledgers?.[String(ledgerIndex)]?.ready + if (!ledgers?.[String(ledgerIndex)]) { + ledgerReady(ledgerIndex) // Create, it'll time out by itself if it's old + } + + return ledgers?.[String(ledgerIndex)]?.ready || Promise.resolve() } const isLedgerReady = ledgerIndex => {