From 4525bd0a374a214eb2cb9b1ee39428867326a00d Mon Sep 17 00:00:00 2001 From: Moumita Date: Mon, 25 Jul 2022 20:31:33 +0530 Subject: [PATCH 1/3] no response error handled --- analytics.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/analytics.js b/analytics.js index e0ef406725..4ab9e14d58 100644 --- a/analytics.js +++ b/analytics.js @@ -169,6 +169,11 @@ class Analytics { processResponse(status, response) { try { logger.debug(`===in process response=== ${status}`); + if (!response) { + logger.debug(`No config found`); + return; + } + if (typeof response === "string") { response = JSON.parse(response); } From e46d3496b05a7afc770ea85a9fe73ba8530d91db Mon Sep 17 00:00:00 2001 From: Moumita <36885121+MoumitaM@users.noreply.github.com> Date: Fri, 29 Jul 2022 13:07:53 +0530 Subject: [PATCH 2/3] Update analytics.js Co-authored-by: Sai Kumar Battinoju <88789928+saikumarrs@users.noreply.github.com> --- analytics.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/analytics.js b/analytics.js index 4ab9e14d58..8c29155413 100644 --- a/analytics.js +++ b/analytics.js @@ -174,9 +174,19 @@ class Analytics { return; } - if (typeof response === "string") { - response = JSON.parse(response); - } +var response = responseVal; +try { + if (typeof responseVal === "string") { + response = JSON.parse(responseVal); + } + + // Do not proceed if the ultimate response value is not an object + if (!response || typeof response !== "object" || Array.isArray(response)) { + throw new Error("Invalid source configuration"); + } +} catch (err) { + handleError(err); +} // Fetch Error reporting enable option from sourceConfig const isErrorReportEnabled = get( From 7daa81c9bc7d1b21cf6b42d9416747739f9cb6c9 Mon Sep 17 00:00:00 2001 From: Moumita Date: Fri, 29 Jul 2022 15:19:13 +0530 Subject: [PATCH 3/3] stop execution in case config error --- analytics.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/analytics.js b/analytics.js index 8c29155413..2397a1b109 100644 --- a/analytics.js +++ b/analytics.js @@ -166,28 +166,25 @@ class Analytics { * @param {*} response * @memberof Analytics */ - processResponse(status, response) { + processResponse(status, responseVal) { try { logger.debug(`===in process response=== ${status}`); - if (!response) { - logger.debug(`No config found`); + + var response = responseVal; + try { + if (typeof responseVal === "string") { + response = JSON.parse(responseVal); + } + + // Do not proceed if the ultimate response value is not an object + if (!response || typeof response !== "object" || Array.isArray(response)) { + throw new Error("Invalid source configuration"); + } + } catch (err) { + handleError(err); return; } -var response = responseVal; -try { - if (typeof responseVal === "string") { - response = JSON.parse(responseVal); - } - - // Do not proceed if the ultimate response value is not an object - if (!response || typeof response !== "object" || Array.isArray(response)) { - throw new Error("Invalid source configuration"); - } -} catch (err) { - handleError(err); -} - // Fetch Error reporting enable option from sourceConfig const isErrorReportEnabled = get( response.source.config,