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 | d2d7dd0561e9ccfbf68caccafffa114a45b29fc0 (patch) | |
tree | cdfd1b028348ecadd53b4d3b1a77c5f117e446aa /api/src/middlewares/ErrorHandler.ts | |
parent | Merge branch 'master' of https://github.com/fosscord/fosscord-api (diff) | |
download | server-d2d7dd0561e9ccfbf68caccafffa114a45b29fc0.tar.xz |
Revert ":construction: webhook"
This reverts commit df2b83ac158be1e7233d8edce59033c15c193599.
Diffstat (limited to 'api/src/middlewares/ErrorHandler.ts')
-rw-r--r-- | api/src/middlewares/ErrorHandler.ts | 7 |
1 files changed, 3 insertions, 4 deletions
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); |