1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-11 05:02:37 +01:00

🐛 fix body parser

This commit is contained in:
Flam3rboy 2021-04-05 21:24:36 +02:00
parent cf70e8cff6
commit c0fd1d1f2f
2 changed files with 4 additions and 3 deletions

View File

@ -23,7 +23,8 @@ export function ErrorHandler(error: Error, req: Request, res: Response, next: Ne
}
res.status(httpcode).json({ code: code, message, errors });
return next();
return;
} catch (error) {
console.error(error);
return res.status(500).json({ code: 500, message: "Internal Server Error" });

View File

@ -114,8 +114,6 @@ export function instanceOf(
}
if (typeof type === "object") {
if (typeof value !== "object") throw new FieldError("BASE_TYPE_OBJECT", req.t("common:field.BASE_TYPE_OBJECT"));
if (Array.isArray(type)) {
if (!Array.isArray(value)) throw new FieldError("BASE_TYPE_ARRAY", req.t("common:field.BASE_TYPE_ARRAY"));
if (!type.length) return true; // type array didn't specify any type
@ -154,6 +152,8 @@ export function instanceOf(
throw new FieldError("BASE_TYPE_CLASS", req.t("common:field.BASE_TYPE_CLASS", { type }));
}
if (typeof value !== "object") throw new FieldError("BASE_TYPE_OBJECT", req.t("common:field.BASE_TYPE_OBJECT"));
const diff = Object.keys(value).missing(
Object.keys(type).map((x) => (x.startsWith(OPTIONAL_PREFIX) ? x.slice(OPTIONAL_PREFIX.length) : x))
);