From 79894e6f27cf1ac116705db9b87e38456c16934a Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Tue, 6 Apr 2021 17:12:05 +0200 Subject: [PATCH] :bug: fix body parser empty error object --- src/util/instanceOf.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/util/instanceOf.ts b/src/util/instanceOf.ts index 869f56d4..b4a231ba 100644 --- a/src/util/instanceOf.ts +++ b/src/util/instanceOf.ts @@ -121,7 +121,8 @@ export function instanceOf( return ( value.every((val, i) => { errors[i] = {}; - return ( + + if ( instanceOf(type[0], val, { path: `${path}[${i}]`, optional, @@ -129,7 +130,12 @@ export function instanceOf( req, ref: { key: i, obj: value }, }) === true - ); + ) { + delete errors[i]; + return true; + } + + return false; }) || errors ); } else if (type?.constructor?.name != "Object") { @@ -170,7 +176,7 @@ export function instanceOf( if (OPTIONAL) newKey = newKey.slice(OPTIONAL_PREFIX.length); errors[newKey] = {}; - return ( + if ( instanceOf(type[key], value[newKey], { path: `${path}.${newKey}`, optional: OPTIONAL, @@ -178,7 +184,12 @@ export function instanceOf( req, ref: { key: newKey, obj: value }, }) === true - ); + ) { + delete errors[newKey]; + return true; + } + + return false; }) || errors ); } else if (typeof type === "number" || typeof type === "string" || typeof type === "boolean") {