From 145cfd762d38098dc6322244a8c026262193ef70 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Sun, 9 Feb 2020 19:47:11 -0800 Subject: [PATCH] handle inner JSON parsing errors --- js/modules/loki_rpc.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/js/modules/loki_rpc.js b/js/modules/loki_rpc.js index 1cd99b9c7..9e7f598c9 100644 --- a/js/modules/loki_rpc.js +++ b/js/modules/loki_rpc.js @@ -85,7 +85,20 @@ const sendToProxy = async (options = {}, targetNode) => { try { const jsonRes = JSON.parse(plaintext); // emulate nodeFetch response... - jsonRes.json = () => JSON.parse(jsonRes.body); + jsonRes.json = () => { + try { + return JSON.parse(jsonRes.body); + } catch(e) { + log.error( + 'lokiRpc sendToProxy error', + e.code, + e.message, + 'json', + jsonRes.body + ); + } + return false; + } return jsonRes; } catch (e) { log.error(