epic_explorer/server/middlewares/error.middleware.ts
2019-07-16 11:47:19 +05:30

20 lines
479 B
TypeScript

import { NextFunction, Request, Response } from 'express';
import { HttpException } from '../exceptions/index';
export function errorMiddleware(
error: HttpException,
request: Request,
response: Response,
next: NextFunction,
) {
const status = error.status || 500;
const message = error.message || 'Internal Server Error';
const timestamp = Date.now();
response.status(status).send({
status,
timestamp,
message,
error: error.error || {},
});
}