From 8175e3f8ed5f06bbaf82d4e7cc3bb911f7020a3e Mon Sep 17 00:00:00 2001 From: Theo D Date: Tue, 17 Sep 2024 23:02:00 +0200 Subject: [PATCH 1/3] fix: handle case of text when invalid JSON (#3119) --- .../components/ResponsePane/QueryResult/index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js index ccf08f3164..cf03a4810c 100644 --- a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js +++ b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js @@ -19,17 +19,21 @@ const formatResponse = (data, mode, filter) => { return ''; } + if (data === null) { + return data; + } + if (mode.includes('json')) { let isValidJSON = false; - + try { isValidJSON = typeof JSON.parse(JSON.stringify(data)) === 'object'; } catch (error) { console.log('Error parsing JSON: ', error.message); } - if (!isValidJSON || data === null) { - return data; + if (!isValidJSON) { + return safeStringifyJSON(data); } if (filter) { @@ -40,7 +44,7 @@ const formatResponse = (data, mode, filter) => { } } - return safeStringifyJSON(data, true); + return safeStringifyJSON(data); } if (mode.includes('xml')) { @@ -48,7 +52,7 @@ const formatResponse = (data, mode, filter) => { if (typeof parsed === 'string') { return parsed; } - return safeStringifyJSON(parsed, true); + return safeStringifyJSON(parsed); } return data; From 3d3bf7ef962d354d08db824f88f5eb55210b5ea4 Mon Sep 17 00:00:00 2001 From: lohit Date: Wed, 18 Sep 2024 14:03:25 +0530 Subject: [PATCH 2/3] don't stringify if json is invalid, and maintain indentation if stringified --- .../src/components/ResponsePane/QueryResult/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js index cf03a4810c..440b798dc0 100644 --- a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js +++ b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js @@ -33,7 +33,7 @@ const formatResponse = (data, mode, filter) => { } if (!isValidJSON) { - return safeStringifyJSON(data); + return data; } if (filter) { @@ -44,7 +44,7 @@ const formatResponse = (data, mode, filter) => { } } - return safeStringifyJSON(data); + return safeStringifyJSON(data, true); } if (mode.includes('xml')) { @@ -52,7 +52,7 @@ const formatResponse = (data, mode, filter) => { if (typeof parsed === 'string') { return parsed; } - return safeStringifyJSON(parsed); + return safeStringifyJSON(parsed, true); } return data; From afad1bcefdd8ebcc8fd51e4ddf46ae30cab01126 Mon Sep 17 00:00:00 2001 From: lohit Date: Wed, 18 Sep 2024 14:14:19 +0530 Subject: [PATCH 3/3] stringify check --- .../bruno-app/src/components/ResponsePane/QueryResult/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js index 440b798dc0..8b233d51ee 100644 --- a/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js +++ b/packages/bruno-app/src/components/ResponsePane/QueryResult/index.js @@ -32,7 +32,7 @@ const formatResponse = (data, mode, filter) => { console.log('Error parsing JSON: ', error.message); } - if (!isValidJSON) { + if (!isValidJSON && typeof data === 'string') { return data; }