1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-14 06:32:36 +01:00

🐛 fix body parser empty error object

This commit is contained in:
Flam3rboy 2021-04-06 17:12:05 +02:00
parent 0f23d5bed4
commit 79894e6f27

View File

@ -121,7 +121,8 @@ export function instanceOf(
return ( return (
value.every((val, i) => { value.every((val, i) => {
errors[i] = {}; errors[i] = {};
return (
if (
instanceOf(type[0], val, { instanceOf(type[0], val, {
path: `${path}[${i}]`, path: `${path}[${i}]`,
optional, optional,
@ -129,7 +130,12 @@ export function instanceOf(
req, req,
ref: { key: i, obj: value }, ref: { key: i, obj: value },
}) === true }) === true
); ) {
delete errors[i];
return true;
}
return false;
}) || errors }) || errors
); );
} else if (type?.constructor?.name != "Object") { } else if (type?.constructor?.name != "Object") {
@ -170,7 +176,7 @@ export function instanceOf(
if (OPTIONAL) newKey = newKey.slice(OPTIONAL_PREFIX.length); if (OPTIONAL) newKey = newKey.slice(OPTIONAL_PREFIX.length);
errors[newKey] = {}; errors[newKey] = {};
return ( if (
instanceOf(type[key], value[newKey], { instanceOf(type[key], value[newKey], {
path: `${path}.${newKey}`, path: `${path}.${newKey}`,
optional: OPTIONAL, optional: OPTIONAL,
@ -178,7 +184,12 @@ export function instanceOf(
req, req,
ref: { key: newKey, obj: value }, ref: { key: newKey, obj: value },
}) === true }) === true
); ) {
delete errors[newKey];
return true;
}
return false;
}) || errors }) || errors
); );
} else if (typeof type === "number" || typeof type === "string" || typeof type === "boolean") { } else if (typeof type === "number" || typeof type === "string" || typeof type === "boolean") {