🚧 webhook

This commit is contained in:
Flam3rboy
2021-09-14 22:15:55 +02:00
parent 8f862f0e5d
commit df2b83ac15
11 changed files with 369 additions and 18 deletions
+2 -2
View File
@@ -5,11 +5,11 @@ import { checkToken, Config } from "@fosscord/util";
export const NO_AUTHORIZATION_ROUTES = [
"/auth/login",
"/auth/register",
"/webhooks/",
"/ping",
"/gateway",
"/experiments",
/\/guilds\/\d+\/widget\.(json|png)/
/\/guilds\/\d+\/widget\.(json|png)/,
/\/webhooks\/\d+\/\w+/ // only exclude webhook calls with webhook token
];
export const API_PREFIX = /^\/api(\/v\d+)?/;
+4 -3
View File
@@ -1,9 +1,10 @@
import { NextFunction, Request, Response } from "express";
import { HTTPError } from "lambert-server";
import { EntityNotFoundError } from "typeorm";
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,8 +19,8 @@ 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`;
} else if (error.name === "EntityNotFoundError") {
message = `${error.message.match(EntityNotFoundErrorRegex)?.[1] || "Item"} could not be found`;
code = 404;
} else if (error instanceof FieldError) {
code = Number(error.code);