From 79f0438079dbd7bf28a606bf77db6e5429c19b2e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 19 Sep 2021 10:20:16 +0200 Subject: [PATCH] Bug Fixed at Platform Client crashing when Http Request Body could not be read. --- Platform/Client/httpInterface.js | 31 +++++++++++-------- .../Foundations/SA/Utilities/HttpRequests.js | 4 ++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Platform/Client/httpInterface.js b/Platform/Client/httpInterface.js index 0932d6e4a..8c6e16536 100644 --- a/Platform/Client/httpInterface.js +++ b/Platform/Client/httpInterface.js @@ -43,7 +43,7 @@ exports.newHttpInterface = function newHttpInterface() { case 'WEB3': { - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { try { @@ -131,7 +131,7 @@ exports.newHttpInterface = function newHttpInterface() { break case 'CCXT': { - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { try { @@ -242,7 +242,7 @@ exports.newHttpInterface = function newHttpInterface() { break } case 'New-Message': { - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) function processRequest(messageReceived) { let timestamp = (new Date()).valueOf() @@ -291,7 +291,7 @@ exports.newHttpInterface = function newHttpInterface() { { switch (requestPath[2]) { // switch by command case 'Save-Node-Schema': { - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { try { @@ -322,7 +322,7 @@ exports.newHttpInterface = function newHttpInterface() { } case 'Save-Concept-Schema': { - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { try { @@ -353,7 +353,7 @@ exports.newHttpInterface = function newHttpInterface() { } case 'Save-Topic-Schema': { - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { try { @@ -384,7 +384,7 @@ exports.newHttpInterface = function newHttpInterface() { } case 'Save-Tutorial-Schema': { - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { try { @@ -415,7 +415,7 @@ exports.newHttpInterface = function newHttpInterface() { } case 'Save-Review-Schema': { - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { try { @@ -446,7 +446,7 @@ exports.newHttpInterface = function newHttpInterface() { } case 'Save-Book-Schema': { - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { try { @@ -991,7 +991,7 @@ exports.newHttpInterface = function newHttpInterface() { related to the Governance System are implemented here and routed to the backend Servers that can process them. */ - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { try { @@ -1412,7 +1412,7 @@ exports.newHttpInterface = function newHttpInterface() { break case 'SavePlugin': { - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { try { @@ -1546,7 +1546,7 @@ exports.newHttpInterface = function newHttpInterface() { break case 'SaveWorkspace': { - SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, processRequest) + SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { @@ -1702,7 +1702,12 @@ exports.newHttpInterface = function newHttpInterface() { } } } catch (err) { - console.log(err.stack) + if (err.stack !== undefined) { + console.log(err.stack) + } + if (err.message !== undefined) { + console.log('[ERROR] onHttpRequest -> err.message = ' + err.message) + } } } } diff --git a/Projects/Foundations/SA/Utilities/HttpRequests.js b/Projects/Foundations/SA/Utilities/HttpRequests.js index 4397491a6..2dc945b1b 100644 --- a/Projects/Foundations/SA/Utilities/HttpRequests.js +++ b/Projects/Foundations/SA/Utilities/HttpRequests.js @@ -6,7 +6,7 @@ exports.newFoundationsUtilitiesHttpRequests = function () { return thisObject - function getRequestBody(httpRequest, callback) { // Gets the de body from a POST httpRequest to the web server + function getRequestBody(httpRequest, httpResponse, callback) { // Gets the de body from a POST httpRequest to the web server try { let body = '' @@ -26,10 +26,12 @@ exports.newFoundationsUtilitiesHttpRequests = function () { httpRequest.on('error', function (err) { console.log('[ERROR] getBody -> err.stack = ' + err.stack) SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) + throw('Not possible to get HTTP Body.') }) } catch (err) { console.log('[ERROR] getBody -> err.stack = ' + err.stack) SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) + throw('Not possible to get HTTP Body.') } } } \ No newline at end of file