mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-03 04:29:09 +01:00
Merge pull request #3676 from pooja-bruno/fix/string-json-response
fix: string json response error
This commit is contained in:
commit
1f2bee1f90
@ -20,14 +20,14 @@ const formatResponse = (data, mode, filter) => {
|
||||
}
|
||||
|
||||
if (data === null) {
|
||||
return data;
|
||||
return 'null';
|
||||
}
|
||||
|
||||
if (mode.includes('json')) {
|
||||
let isValidJSON = false;
|
||||
|
||||
try {
|
||||
isValidJSON = typeof JSON.parse(JSON.stringify(data)) === 'object';
|
||||
isValidJSON = typeof JSON.parse(JSON.stringify(data)) === 'object'
|
||||
} catch (error) {
|
||||
console.log('Error parsing JSON: ', error.message);
|
||||
}
|
||||
|
@ -365,11 +365,15 @@ const parseDataFromResponse = (response, disableParsingResponseJson = false) =>
|
||||
try {
|
||||
// Filter out ZWNBSP character
|
||||
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
|
||||
|
||||
// If the response is a string and starts and ends with double quotes, it's a stringified JSON and should not be parsed
|
||||
data = data.replace(/^\uFEFF/, '');
|
||||
if (!disableParsingResponseJson) {
|
||||
if ( !disableParsingResponseJson && ! (typeof data === 'string' && data.startsWith("\"") && data.endsWith("\""))) {
|
||||
data = JSON.parse(data);
|
||||
}
|
||||
} catch { }
|
||||
} catch {
|
||||
console.log('Failed to parse response data as JSON');
|
||||
}
|
||||
|
||||
return { data, dataBuffer };
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user