From d75327b92eb2d0cd83a11b9a1112304ba0343970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilja=20Gu=C5=BEovski?= Date: Sun, 15 Oct 2023 22:16:13 +0300 Subject: [PATCH 1/2] fix verifyChanges causing 0: {, 1: } during insert and patch --- src/helpers/get-user-data.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/helpers/get-user-data.ts b/src/helpers/get-user-data.ts index 28e9140..8e96860 100644 --- a/src/helpers/get-user-data.ts +++ b/src/helpers/get-user-data.ts @@ -97,6 +97,10 @@ export function getUserData ( const user = checkOneUser(users); + if (typeof user.verifyChanges === "string" && user.verifyChanges[0] === "{") { + user.verifyChanges = JSON.parse(user.verifyChanges); + } + checkUserChecks(user, checks); return user; From c97b82c1063a0be9ea79d3b078c566cbef994014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilja=20Gu=C5=BEovski?= Date: Mon, 16 Oct 2023 18:42:25 +0300 Subject: [PATCH 2/2] Try to parse with json parse and provide better error reporting --- src/helpers/get-user-data.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/helpers/get-user-data.ts b/src/helpers/get-user-data.ts index 8e96860..ab79a39 100644 --- a/src/helpers/get-user-data.ts +++ b/src/helpers/get-user-data.ts @@ -97,8 +97,14 @@ export function getUserData ( const user = checkOneUser(users); - if (typeof user.verifyChanges === "string" && user.verifyChanges[0] === "{") { - user.verifyChanges = JSON.parse(user.verifyChanges); + if (typeof user.verifyChanges === "string") { + try { + user.verifyChanges = JSON.parse(user.verifyChanges); + } catch (e) { + throw new Error( + "Cannot parse user.verifyChanges string field. Incorrect JSON string provided: " + user.verifyChanges + ); + } } checkUserChecks(user, checks);