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

fix: if response is not valid json throw error #409

This commit is contained in:
2021-06-21 00:45:37 +05:00
parent 9b976d48ca
commit 93c9a34591
4 changed files with 35 additions and 2 deletions

View File

@@ -12,3 +12,4 @@ export * from './serialize'
export * from './splitChunks'
export * from './parseWeboutResponse'
export * from './fetchLogByChunks'
export * from './isValidJson'

11
src/utils/isValidJson.ts Normal file
View File

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