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

fix: predefine jsonParseArrayError message

This commit is contained in:
2021-08-18 16:09:51 +05:00
parent 78149e6c54
commit e72195ca5d
2 changed files with 3 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
export class JsonParseArrayError extends Error { export class JsonParseArrayError extends Error {
constructor(public message: string) { constructor() {
super(message) super('Can not parse array object to json.')
this.name = 'JsonParseArrayError' this.name = 'JsonParseArrayError'
Object.setPrototypeOf(this, JsonParseArrayError.prototype) Object.setPrototypeOf(this, JsonParseArrayError.prototype)
} }

View File

@@ -6,8 +6,7 @@ import { JsonParseArrayError, InvalidJsonError } from '../types/errors'
*/ */
export const getValidJson = (str: string | object) => { export const getValidJson = (str: string | object) => {
try { try {
const arrayErrorMessage = 'Can not parse array object to json.' if (Array.isArray(str)) throw new JsonParseArrayError()
if (Array.isArray(str)) throw new JsonParseArrayError(arrayErrorMessage)
if (typeof str === 'object') return str if (typeof str === 'object') return str