diff --git a/api/src/middlewares/BodyParser.ts b/api/src/middlewares/BodyParser.ts
index b0ff699d..4cb376bc 100644
--- a/api/src/middlewares/BodyParser.ts
+++ b/api/src/middlewares/BodyParser.ts
@@ -6,6 +6,8 @@ export function BodyParser(opts?: OptionsJson) {
const jsonParser = bodyParser.json(opts);
return (req: Request, res: Response, next: NextFunction) => {
+ if (!req.headers["content-type"]) req.headers["content-type"] = "application/json";
+
jsonParser(req, res, (err) => {
if (err) {
// TODO: different errors for body parser (request size limit, wrong body type, invalid body, ...)
diff --git a/api/src/middlewares/ErrorHandler.ts b/api/src/middlewares/ErrorHandler.ts
index be2586cf..96e703ce 100644
--- a/api/src/middlewares/ErrorHandler.ts
+++ b/api/src/middlewares/ErrorHandler.ts
@@ -1,8 +1,9 @@
import { NextFunction, Request, Response } from "express";
import { HTTPError } from "lambert-server";
import { EntityNotFoundError } from "typeorm";
-import { FieldError } from "../util/instanceOf";
+import { FieldError } from "@fosscord/api";
import { ApiError } from "@fosscord/util";
+const EntityNotFoundErrorRegex = /"(\w+)"/;
export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) {
if (!error) return next();
@@ -18,9 +19,9 @@ export function ErrorHandler(error: Error, req: Request, res: Response, next: Ne
code = error.code;
message = error.message;
httpcode = error.httpStatus;
- } else if (error instanceof EntityNotFoundError) {
- message = `${(error as any).stringifyTarget || "Item"} could not be found`;
- code = 404;
+ } else if (error.name === "EntityNotFoundError") {
+ message = `${error.message.match(EntityNotFoundErrorRegex)?.[1] || "Item"} could not be found`;
+ code = httpcode = 404;
} else if (error instanceof FieldError) {
code = Number(error.code);
message = error.message;
diff --git a/api/src/middlewares/RateLimit.ts b/api/src/middlewares/RateLimit.ts
index dffbc0d9..1a38cfcf 100644
--- a/api/src/middlewares/RateLimit.ts
+++ b/api/src/middlewares/RateLimit.ts
@@ -1,6 +1,6 @@
import { Config, listenEvent } from "@fosscord/util";
import { NextFunction, Request, Response, Router } from "express";
-import { getIpAdress } from "../util/ipAddress";
+import { getIpAdress } from "@fosscord/api";
import { API_PREFIX_TRAILING_SLASH } from "./Authentication";
// Docs: https://discord.com/developers/docs/topics/rate-limits
@@ -107,7 +107,8 @@ export default function rateLimit(opts: {
}
export async function initRateLimits(app: Router) {
- const { routes, global, ip, error } = Config.get().limits.rate;
+ const { routes, global, ip, error, disabled } = Config.get().limits.rate;
+ if (disabled) return;
await listenEvent(EventRateLimit, (event) => {
Cache.set(event.channel_id as string, event.data);
event.acknowledge?.();
|