From 4a0a5e48cd7355de8dd905e103329cdf8c7e217c Mon Sep 17 00:00:00 2001 From: DmitryPogodaev Date: Fri, 18 Sep 2020 12:26:51 +0400 Subject: [PATCH] Update helpers.js fix: unhandled exception when rpc answer not in json format --- src/helpers.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/helpers.js b/src/helpers.js index c15ca96..21a02f0 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -76,7 +76,12 @@ export async function ethCall(rawData, { id, web3, rpcUrl, block, multicallAddre })); function onMessage(data) { if (typeof data !== 'string') data = data.data; - const json = JSON.parse(data); + try { + var json = JSON.parse(data); + } catch (e) { + log('Unexpected WebSocket response %s', data); + return; + } if (!json.id || json.id !== id) return; log('Got WebSocket response id #%d', json.id); clearTimeout(timeoutHandle);