From a5d341ee897cf03d3740e3905490639c099b0abb Mon Sep 17 00:00:00 2001 From: praveen-klaytn Date: Mon, 14 Oct 2024 13:55:10 +0800 Subject: [PATCH] Added error handling --- app.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/app.js b/app.js index 92b1416..26e0c4e 100644 --- a/app.js +++ b/app.js @@ -71,21 +71,27 @@ const UNIQUE_ACTIVE_CONTRACTS_SQL = `WITH from_addresses AS ( FROM active_contracts`; const loadData = async (_query, _dataElement) => { - const queryResultSetTxnCount = await flipside.query.run({ sql: _query }); - - let results = await flipside.query.getQueryResults({ - queryRunId: queryResultSetTxnCount.queryId, - pageNumber: 1, - pageSize: 1, - }); - - if (results.error) { - throw results.error; - } - if (results.records && results.records.length > 0) { - StatsData[_dataElement] = results.records[0][_dataElement]; - console.log(`Updated ${_dataElement}: ` + results.records[0][_dataElement]); + try { + const queryResultSetTxnCount = await flipside.query.run({ sql: _query }); + + let results = await flipside.query.getQueryResults({ + queryRunId: queryResultSetTxnCount.queryId, + pageNumber: 1, + pageSize: 1, + }); + + if (results.error) { + throw results.error; + } + if (results.records && results.records.length > 0) { + StatsData[_dataElement] = results.records[0][_dataElement]; + console.log(`Updated ${_dataElement}: ` + results.records[0][_dataElement]); + } + } catch(err) { + console.log("Error while fetching "+_dataElement) + console.log(err); } + }; const loadCoingeckoData = (_dataElement) => {