diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-16 20:49:07 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-16 20:49:07 +0200 |
commit | 1cd4b819171f9bbadb00b2e87d1a710ead355f95 (patch) | |
tree | e66bff65da570bd9d3c4c247ae84b4826bb302e6 /api/src/middlewares | |
parent | Merge branch 'master' of https://github.com/fosscord/fosscord-api (diff) | |
download | server-1cd4b819171f9bbadb00b2e87d1a710ead355f95.tar.xz |
Revert ":construction: webhook"
This reverts commit f691aa4c5aa47c8a8085c7b01912a1c403ce8732.
Diffstat (limited to 'api/src/middlewares')
-rw-r--r-- | api/src/middlewares/Authentication.ts | 4 | ||||
-rw-r--r-- | api/src/middlewares/ErrorHandler.ts | 7 |
2 files changed, 5 insertions, 6 deletions
diff --git a/api/src/middlewares/Authentication.ts b/api/src/middlewares/Authentication.ts index 32307f42..a300c786 100644 --- a/api/src/middlewares/Authentication.ts +++ b/api/src/middlewares/Authentication.ts @@ -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)/, - /\/webhooks\/\d+\/\w+/ // only exclude webhook calls with webhook token + /\/guilds\/\d+\/widget\.(json|png)/ ]; export const API_PREFIX = /^\/api(\/v\d+)?/; diff --git a/api/src/middlewares/ErrorHandler.ts b/api/src/middlewares/ErrorHandler.ts index 338da8d5..d288f3fb 100644 --- a/api/src/middlewares/ErrorHandler.ts +++ b/api/src/middlewares/ErrorHandler.ts @@ -1,10 +1,9 @@ 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(); @@ -19,8 +18,8 @@ export function ErrorHandler(error: Error, req: Request, res: Response, next: Ne code = error.code; message = error.message; httpcode = error.httpStatus; - } else if (error.name === "EntityNotFoundError") { - message = `${error.message.match(EntityNotFoundErrorRegex)?.[1] || "Item"} could not be found`; + } else if (error instanceof EntityNotFoundError) { + message = `${(error as any).stringifyTarget || "Item"} could not be found`; code = 404; } else if (error instanceof FieldError) { code = Number(error.code); |