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;
|