2018-07-08 14:02:05 -06:00
|
|
|
import * as express from "express";
|
|
|
|
|
|
|
|
import ApiError from "@common/ApiError";
|
|
|
|
|
|
|
|
const errorHandler: express.ErrorRequestHandler =
|
|
|
|
(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
if (err instanceof ApiError) {
|
|
|
|
res.status(err.statusCode).json(err.toJSON());
|
|
|
|
} else {
|
|
|
|
next(err);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-25 12:53:33 -06:00
|
|
|
export default errorHandler;
|