summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-06 17:12:05 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-06 17:12:05 +0200
commit79894e6f27cf1ac116705db9b87e38456c16934a (patch)
treeb0ebd926cc27c1d4db107229cae3cd3f3ddc1ac8
parentMerge pull request #81 from notsapinho/patch-1 (diff)
downloadserver-79894e6f27cf1ac116705db9b87e38456c16934a.tar.xz
:bug: fix body parser empty error object
-rw-r--r--src/util/instanceOf.ts19
1 files 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") {