mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-26 15:01:40 +02:00
* fix: handle case of text when invalid JSON (#3119) * don't stringify if json is invalid, and maintain indentation if stringified * stringify check --------- Co-authored-by: lohit <lohxt.space@gmail.com>
This commit is contained in:
parent
8b6e55dfc0
commit
938e0560a2
@ -19,16 +19,20 @@ const formatResponse = (data, mode, filter) => {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data === null) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
if (mode.includes('json')) {
|
if (mode.includes('json')) {
|
||||||
let isValidJSON = false;
|
let isValidJSON = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
isValidJSON = typeof JSON.parse(JSON.stringify(data)) === 'object';
|
isValidJSON = typeof JSON.parse(JSON.stringify(data)) === 'object';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Error parsing JSON: ', error.message);
|
console.log('Error parsing JSON: ', error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidJSON || data === null) {
|
if (!isValidJSON && typeof data === 'string') {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user