From 466f12de16fe7b406f0c9efe831de6f89514a0fe Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Mon, 24 Feb 2020 18:40:42 -0400 Subject: [PATCH] retry on undefined --- services/gunDB/contact-api/actions.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index af3942c4..eb8413aa 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -518,8 +518,8 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => { const lastRequestIDSentToUser = maybeLastRequestIDSentToUser console.log('sendHR() -> before alreadyContactedOnCurrHandshakeNode') - /** @type {boolean} */ - const alreadyContactedOnCurrHandshakeNode = await Utils.tryAndWait( + + const hrInHandshakeNode = await Utils.tryAndWait( gun => new Promise(res => { gun @@ -527,11 +527,16 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => { .get(currentHandshakeAddress) .get(lastRequestIDSentToUser) .once(data => { - res(typeof data !== 'undefined') + res(data) }) - }) + }), + // force retry on undefined in case the undefined was a false negative + v => typeof v === 'undefined' ) + const alreadyContactedOnCurrHandshakeNode = + typeof hrInHandshakeNode !== 'undefined' + if (alreadyContactedOnCurrHandshakeNode) { throw new Error(ErrorCode.ALREADY_REQUESTED_HANDSHAKE) }