summary refs log tree commit diff
path: root/api/src/middlewares/ErrorHandler.ts
diff options
context:
space:
mode:
authorAlTech98 <altech123159@gmail.com>2021-08-31 17:56:38 +0200
committerAlTech98 <altech123159@gmail.com>2021-08-31 17:56:38 +0200
commit7baa2fbe52bc2302fe6dcb062594316944c87a92 (patch)
tree1d398263ec9235d2433e6ef7edd8b0493798c272 /api/src/middlewares/ErrorHandler.ts
parentMerge pull request #297 from AlTech98/typeorm (diff)
downloadserver-7baa2fbe52bc2302fe6dcb062594316944c87a92.tar.xz
Created list of all possible api errors and made them throwable in routes code
Diffstat (limited to 'api/src/middlewares/ErrorHandler.ts')
-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 0ed37bb4..5fc36f33 100644
--- a/api/src/middlewares/ErrorHandler.ts
+++ b/api/src/middlewares/ErrorHandler.ts
@@ -1,6 +1,7 @@
 import { NextFunction, Request, Response } from "express";
 import { HTTPError } from "lambert-server";
 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) {
@@ -13,6 +14,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 FieldError) {
 			code = Number(error.code);
 			message = error.message;