mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-09 05:20:05 +00:00
fix: throw error if null or undefined is passed to getValidJson
This commit is contained in:
@@ -33,4 +33,18 @@ describe('jsonValidator', () => {
|
|||||||
}
|
}
|
||||||
expect(test).toThrow(JsonParseArrayError)
|
expect(test).toThrow(JsonParseArrayError)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should throw an error when null is passed', () => {
|
||||||
|
const test = () => {
|
||||||
|
getValidJson(null as any)
|
||||||
|
}
|
||||||
|
expect(test).toThrow(InvalidJsonError)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should throw an error when undefined is passed', () => {
|
||||||
|
const test = () => {
|
||||||
|
getValidJson(undefined as any)
|
||||||
|
}
|
||||||
|
expect(test).toThrow(InvalidJsonError)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { JsonParseArrayError, InvalidJsonError } from '../types/errors'
|
|||||||
*/
|
*/
|
||||||
export const getValidJson = (str: string | object) => {
|
export const getValidJson = (str: string | object) => {
|
||||||
try {
|
try {
|
||||||
|
if (str === null || str === undefined) throw new InvalidJsonError()
|
||||||
|
|
||||||
if (Array.isArray(str)) throw new JsonParseArrayError()
|
if (Array.isArray(str)) throw new JsonParseArrayError()
|
||||||
|
|
||||||
if (typeof str === 'object') return str
|
if (typeof str === 'object') return str
|
||||||
|
|||||||
Reference in New Issue
Block a user