epic_explorer/server/middlewares/error.middleware.ts

20 lines
479 B
TypeScript
Raw Permalink Normal View History

2019-07-09 09:22:36 +00:00
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 || {},
});
}