🐛 fix error handler
This commit is contained in:
parent
fe9e5a9e47
commit
9b95834b4b
BIN
package-lock.json
generated
BIN
package-lock.json
generated
Binary file not shown.
@ -29,7 +29,7 @@
|
||||
"i18next-http-middleware": "^3.1.0",
|
||||
"i18next-node-fs-backend": "^2.1.3",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"lambert-db": "^1.1.6",
|
||||
"lambert-db": "^1.1.8",
|
||||
"lambert-server": "^1.0.10",
|
||||
"missing-native-js-functions": "^1.2.2",
|
||||
"node-fetch": "^2.6.1"
|
||||
|
||||
@ -3,6 +3,7 @@ import { HTTPError } from "lambert-server";
|
||||
import { FieldError } from "../util/instanceOf";
|
||||
|
||||
export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
let code = 400;
|
||||
let httpcode = code;
|
||||
let message = error?.toString();
|
||||
@ -23,4 +24,8 @@ export function ErrorHandler(error: Error, req: Request, res: Response, next: Ne
|
||||
|
||||
res.status(httpcode).json({ code: code, message, errors });
|
||||
return next();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({ code: 500, message: "Internal Server Error" });
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,9 @@ import { NextFunction, Request, Response } from "express";
|
||||
import Config from "../util/Config";
|
||||
import { db } from "discord-server-util";
|
||||
|
||||
// TODO: use mongodb ttl index
|
||||
// TODO: increment count on serverside
|
||||
|
||||
export async function GlobalRateLimit(req: Request, res: Response, next: NextFunction) {
|
||||
if (!Config.get().limits.rate.ip.enabled) return next();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user