🐛 fix error handler
This commit is contained in:
parent
fe9e5a9e47
commit
9b95834b4b
14
package-lock.json
generated
14
package-lock.json
generated
@ -18,7 +18,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"
|
||||
@ -1078,9 +1078,9 @@
|
||||
"integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ=="
|
||||
},
|
||||
"node_modules/lambert-db": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.6.tgz",
|
||||
"integrity": "sha512-FbUNAbgPYUvfJSxLdcfIk6w8J+Z4IYZJasVURBMm4eOeLm//kgGeOi+SrJqqa5z+gaCJ65ENIVs2hd+Cj2Efbw==",
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.8.tgz",
|
||||
"integrity": "sha512-EyIEYLppS54tXsxIXGuS0l/0c+tF86KvaXRR92yRcGp5CHWRxPfUqV0KX/Ft7OkqtRTK5tDuJ/Bb4kUCXh2VUg==",
|
||||
"dependencies": {
|
||||
"missing-native-js-functions": "^1.1.8",
|
||||
"mongodb": "^3.6.2",
|
||||
@ -3247,9 +3247,9 @@
|
||||
"integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ=="
|
||||
},
|
||||
"lambert-db": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.6.tgz",
|
||||
"integrity": "sha512-FbUNAbgPYUvfJSxLdcfIk6w8J+Z4IYZJasVURBMm4eOeLm//kgGeOi+SrJqqa5z+gaCJ65ENIVs2hd+Cj2Efbw==",
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.8.tgz",
|
||||
"integrity": "sha512-EyIEYLppS54tXsxIXGuS0l/0c+tF86KvaXRR92yRcGp5CHWRxPfUqV0KX/Ft7OkqtRTK5tDuJ/Bb4kUCXh2VUg==",
|
||||
"requires": {
|
||||
"missing-native-js-functions": "^1.1.8",
|
||||
"mongodb": "^3.6.2",
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user