1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-07 20:40:05 +00:00

fix: replace isValidJson with getValidJson

This commit is contained in:
2021-07-18 23:24:22 +05:00
parent 7ac7c5e52b
commit 5347aeba09
6 changed files with 14 additions and 14 deletions

13
src/utils/getValidJson.ts Normal file
View File

@@ -0,0 +1,13 @@
/**
* Checks if string is in valid JSON format else throw error.
* @param str - string to check.
*/
export const getValidJson = (str: string | object) => {
try {
if (typeof str === 'object') return str
return JSON.parse(str)
} catch (e) {
throw new Error('Invalid JSON response.')
}
}