Skip to content

Commit

Permalink
fix: handle case of text when invalid JSON (usebruno#3119) (usebruno#…
Browse files Browse the repository at this point in the history
…3120)

* fix: handle case of text when invalid JSON (usebruno#3119)

* don't stringify if json is invalid, and maintain indentation if stringified

* stringify check

---------

Co-authored-by: lohit <[email protected]>
  • Loading branch information
TheoD02 and lohxt1 authored Sep 18, 2024
1 parent 8b6e55d commit 938e056
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ 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) {
if (!isValidJSON && typeof data === 'string') {
return data;
}

Expand Down

0 comments on commit 938e056

Please sign in to comment.