Skip to content

Commit

Permalink
add decomment step in a try catch block (#2485)
Browse files Browse the repository at this point in the history
* add decomment step in a try catch block

* request params validation - fix unit tests
  • Loading branch information
lohxt1 authored Jun 21, 2024
1 parent 929d2b5 commit b031e1f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 7 additions & 2 deletions packages/bruno-cli/src/runner/prepare-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
13 changes: 9 additions & 4 deletions packages/bruno-electron/src/ipc/network/prepare-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit b031e1f

Please sign in to comment.