From 6c8c7c27edacf5877a7d8ce8440c7ece1ee5115a Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Mon, 24 Feb 2020 15:11:17 -0400 Subject: [PATCH] use tryAndWait() --- services/gunDB/contact-api/utils/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/gunDB/contact-api/utils/index.js b/services/gunDB/contact-api/utils/index.js index c5bb369c..e1fef163 100644 --- a/services/gunDB/contact-api/utils/index.js +++ b/services/gunDB/contact-api/utils/index.js @@ -206,12 +206,18 @@ const recipientToOutgoingID = async recipientPub => { * @returns {Promise} */ const currHandshakeAddress = async userPub => { - const maybeAddr = await tryAndWait(gun => - gun + const maybeAddr = await tryAndWait(async gun => { + const addr = await gun .user(userPub) .get(Key.CURRENT_HANDSHAKE_ADDRESS) .then() - ) + + if (typeof addr !== 'string' && addr !== null) { + throw new TypeError('Expected handshake address to be string or null') + } + + return addr + }) return typeof maybeAddr === 'string' ? maybeAddr : null }