summary refs log tree commit diff
path: root/api/src/middlewares
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-31 18:13:16 +0200
committerGitHub <noreply@github.com>2021-08-31 18:13:16 +0200
commit98f39f4710c5be43f31f52c62f1f0460cff506cd (patch)
tree1c9708b20b8e49d0cae48cba1030558dbbb07db8 /api/src/middlewares
parentMerge branch 'typeorm' of https://github.com/fosscord/fosscord-api into typeorm (diff)
parentMerge branch 'typeorm' into typeorm (diff)
downloadserver-98f39f4710c5be43f31f52c62f1f0460cff506cd.tar.xz
Merge pull request #299 from AlTech98/typeorm
Created list of all possible api errors and made them throwable in routes code
Diffstat (limited to 'api/src/middlewares')
-rw-r--r--api/src/middlewares/ErrorHandler.ts6
1 files changed, 6 insertions, 0 deletions
diff --git a/api/src/middlewares/ErrorHandler.ts b/api/src/middlewares/ErrorHandler.ts

index e1ab592c..f061172a 100644 --- a/api/src/middlewares/ErrorHandler.ts +++ b/api/src/middlewares/ErrorHandler.ts
@@ -2,6 +2,7 @@ import { NextFunction, Request, Response } from "express"; import { HTTPError } from "lambert-server"; import { EntityNotFoundError } from "typeorm"; import { FieldError } from "../util/instanceOf"; +import {ApiError} from "../util/ApiError"; // TODO: update with new body/typorm validation export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) { @@ -14,6 +15,11 @@ export function ErrorHandler(error: Error, req: Request, res: Response, next: Ne let errors = undefined; if (error instanceof HTTPError && error.code) code = httpcode = error.code; + else if (error instanceof ApiError) { + code = error.code; + message = error.message; + httpcode = error.httpStatus; + } else if (error instanceof EntityNotFoundError) { message = `${(error as any).stringifyTarget} can not be found`; code = 404;