1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 01:14:36 +00:00

chore: preventing double parse of invalid json check

This commit is contained in:
2021-07-12 11:02:01 +02:00
parent db372950b4
commit 4466ee30d2

View File

@@ -4,8 +4,9 @@
*/
export const isValidJson = (str: string | object) => {
try {
str = typeof str !== 'string' ? JSON.stringify(str) : str
JSON.parse(str)
if (typeof str === 'object') return
str = JSON.parse(str)
} catch (e) {
throw new Error('Invalid JSON response.')
}