From 724350ebd74843897e93ef8121d7a65449ed0270 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sun, 2 Aug 2020 13:13:20 -0400 Subject: [PATCH] first retry should be quickly after first try --- services/gunDB/contact-api/utils/index.js | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/services/gunDB/contact-api/utils/index.js b/services/gunDB/contact-api/utils/index.js index 89b53180..81b12fad 100644 --- a/services/gunDB/contact-api/utils/index.js +++ b/services/gunDB/contact-api/utils/index.js @@ -116,6 +116,36 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => { ` args: ${promGen.toString()} -- ${shouldRetry.toString()}` ) + await delay(200) + + try { + resolvedValue = await timeout5( + promGen( + require('../../Mediator/index').getGun(), + require('../../Mediator/index').getUser() + ) + ) + + if (shouldRetry(resolvedValue)) { + logger.info( + 'force retrying' + + ` args: ${promGen.toString()} -- ${shouldRetry.toString()} \n resolvedValue: ${resolvedValue}, type: ${typeof resolvedValue}` + ) + } else { + return resolvedValue + } + } catch (e) { + logger.error(e) + if (e.message === 'NOT_AUTH') { + throw e + } + } + + logger.info( + `\n retrying \n` + + ` args: ${promGen.toString()} -- ${shouldRetry.toString()}` + ) + await delay(3000) try {