From 7fcb68f0825b99a830f7c1ee24bd58a456c1ed5b Mon Sep 17 00:00:00 2001 From: AlTech98 Date: Tue, 31 Aug 2021 17:56:38 +0200 Subject: Created list of all possible api errors and made them throwable in routes code --- api/src/middlewares/ErrorHandler.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'api/src/middlewares/ErrorHandler.ts') 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; -- cgit 1.5.1