summary refs log tree commit diff
path: root/api/src/middlewares/ErrorHandler.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-14 22:15:55 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-14 22:15:55 +0200
commitf691aa4c5aa47c8a8085c7b01912a1c403ce8732 (patch)
tree532673ee0955f5eec2c8a33c7abad8ed64dc9a48 /api/src/middlewares/ErrorHandler.ts
parentfix #129 (diff)
downloadserver-f691aa4c5aa47c8a8085c7b01912a1c403ce8732.tar.xz
:construction: webhook
Diffstat (limited to 'api/src/middlewares/ErrorHandler.ts')
-rw-r--r--api/src/middlewares/ErrorHandler.ts7
1 files changed, 4 insertions, 3 deletions
diff --git a/api/src/middlewares/ErrorHandler.ts b/api/src/middlewares/ErrorHandler.ts

index d288f3fb..338da8d5 100644 --- a/api/src/middlewares/ErrorHandler.ts +++ b/api/src/middlewares/ErrorHandler.ts
@@ -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);