From b1724b86f27940698247ed71115323d8ddd16b0c Mon Sep 17 00:00:00 2001 From: Kirill Tronin Date: Fri, 16 Sep 2022 18:55:41 +0700 Subject: [PATCH] simplify error catching --- src/index.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 1323d66..544f971 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ const { decodeTxRaw } = require("@cosmjs/proto-signing"); const { co } = require("co"); const config = require("../config.json"); -const { saveProcessedTx, getLastProcessedTxs, dbReady, createEmptyBlock } = require("./db"); +const { getLastProcessedTxs, dbReady, createEmptyBlock } = require("./db"); const msgHandlers = require("./messages"); const { getTxsInBlock, getNewHeight } = require("./requests"); const { registerNetwork } = require("./endpoints"); @@ -20,13 +20,10 @@ const processNewTx = async (network, newtx) => { let msgLog = newtx?.log?.find(x => i === 0 ? !x.msg_index : x.msg_index === i); let handler = msgHandlers[msg.typeUrl]; - return (async () => { - try { - return handler(network, msg, newtx, msgLog) - } catch (err) { - console.error(`Error handling tx in ${network.name} msg ${err?.message}`) - } - })(); + return handler(network, msg, newtx, msgLog) + .catch((err) => { + console.error(`Error handling txid ${newtx.hash} in ${network.name} msg ${err?.message}`) + }); }); await Promise.all(handlers);