From b031e1f00976065af3753f1623bbbaa9b867719a Mon Sep 17 00:00:00 2001 From: lohit Date: Fri, 21 Jun 2024 10:45:12 +0530 Subject: [PATCH] add decomment step in a try catch block (#2485) * add decomment step in a try catch block * request params validation - fix unit tests --- packages/bruno-cli/src/runner/prepare-request.js | 9 +++++++-- .../src/ipc/network/prepare-request.js | 13 +++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/bruno-cli/src/runner/prepare-request.js b/packages/bruno-cli/src/runner/prepare-request.js index eab44f8c0..aaeb15441 100644 --- a/packages/bruno-cli/src/runner/prepare-request.js +++ b/packages/bruno-cli/src/runner/prepare-request.js @@ -76,10 +76,15 @@ const prepareRequest = (request, collectionRoot) => { if (!contentTypeDefined) { axiosRequest.headers['content-type'] = 'application/json'; } - const jsonBody = decomment(request.body.json); + let jsonBody; + try { + jsonBody = decomment(request?.body?.json); + } catch (error) { + jsonBody = request?.body?.json; + } try { axiosRequest.data = JSONbig.parse(jsonBody); - } catch (ex) { + } catch (error) { axiosRequest.data = jsonBody; } } diff --git a/packages/bruno-electron/src/ipc/network/prepare-request.js b/packages/bruno-electron/src/ipc/network/prepare-request.js index bd09619f4..73b8bf71c 100644 --- a/packages/bruno-electron/src/ipc/network/prepare-request.js +++ b/packages/bruno-electron/src/ipc/network/prepare-request.js @@ -172,11 +172,16 @@ const prepareRequest = (request, collectionRoot, collectionPath) => { if (!contentTypeDefined) { axiosRequest.headers['content-type'] = 'application/json'; } - const body = decomment(request.body.json); + let jsonBody; try { - axiosRequest.data = JSONbig.parse(body); - } catch (ex) { - axiosRequest.data = body; + jsonBody = decomment(request?.body?.json); + } catch (error) { + jsonBody = request?.body?.json; + } + try { + axiosRequest.data = JSONbig.parse(jsonBody); + } catch (error) { + axiosRequest.data = jsonBody; } }