From 4466ee30d2c60cf3e23c72d09787b163a69fa696 Mon Sep 17 00:00:00 2001 From: Mihajlo Date: Mon, 12 Jul 2021 11:02:01 +0200 Subject: [PATCH] chore: preventing double parse of invalid json check --- src/utils/isValidJson.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/isValidJson.ts b/src/utils/isValidJson.ts index d9bf83b..d6cc549 100644 --- a/src/utils/isValidJson.ts +++ b/src/utils/isValidJson.ts @@ -4,8 +4,9 @@ */ export const isValidJson = (str: string | object) => { try { - str = typeof str !== 'string' ? JSON.stringify(str) : str - JSON.parse(str) + if (typeof str === 'object') return + + str = JSON.parse(str) } catch (e) { throw new Error('Invalid JSON response.') }