From e004adad9bbd2d547b8b0f40f0d627c1814ee707 Mon Sep 17 00:00:00 2001 From: Mohammad Hossein Ebadollahi Date: Fri, 7 Jul 2023 04:16:41 +0330 Subject: [PATCH 1/2] Catch JSON.parse errors --- Client.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Client.js b/Client.js index 83dbb2d..8a00a85 100644 --- a/Client.js +++ b/Client.js @@ -21,7 +21,13 @@ Client.prototype.makeRequest = function makeRequest(controller, action, paramete path: '/api/v1/' + controller + '/' + action }, function (response) { response.pipe(concatStream(function (content) { - var json = JSON.parse(content); + var json + try { + json = JSON.parse(content); + } catch (error) { + reject(error); + } + if (json.status === 'success') { resolve(json.data); } else { From c488b070f79716391fa54ba854fc4cff6e781ed5 Mon Sep 17 00:00:00 2001 From: Mohammad Hossein Ebadollahi Date: Fri, 7 Jul 2023 04:17:23 +0330 Subject: [PATCH 2/2] Update Client.js --- Client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client.js b/Client.js index 8a00a85..9adbe5a 100644 --- a/Client.js +++ b/Client.js @@ -25,7 +25,7 @@ Client.prototype.makeRequest = function makeRequest(controller, action, paramete try { json = JSON.parse(content); } catch (error) { - reject(error); + return reject(error); } if (json.status === 'success') {