From e72195ca5d0774a58bf710842a9fcdadb8412481 Mon Sep 17 00:00:00 2001 From: sabhas Date: Wed, 18 Aug 2021 16:09:51 +0500 Subject: [PATCH] fix: predefine jsonParseArrayError message --- src/types/errors/JsonParseArrayError.ts | 4 ++-- src/utils/getValidJson.ts | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/types/errors/JsonParseArrayError.ts b/src/types/errors/JsonParseArrayError.ts index 9006f64..ad08ecd 100644 --- a/src/types/errors/JsonParseArrayError.ts +++ b/src/types/errors/JsonParseArrayError.ts @@ -1,6 +1,6 @@ export class JsonParseArrayError extends Error { - constructor(public message: string) { - super(message) + constructor() { + super('Can not parse array object to json.') this.name = 'JsonParseArrayError' Object.setPrototypeOf(this, JsonParseArrayError.prototype) } diff --git a/src/utils/getValidJson.ts b/src/utils/getValidJson.ts index 565ee98..17f9cbb 100644 --- a/src/utils/getValidJson.ts +++ b/src/utils/getValidJson.ts @@ -6,8 +6,7 @@ import { JsonParseArrayError, InvalidJsonError } from '../types/errors' */ export const getValidJson = (str: string | object) => { try { - const arrayErrorMessage = 'Can not parse array object to json.' - if (Array.isArray(str)) throw new JsonParseArrayError(arrayErrorMessage) + if (Array.isArray(str)) throw new JsonParseArrayError() if (typeof str === 'object') return str