import { Middleware, StatusCodes, Request, Response, NextFunction } from '../base/http';
import { $$ } from '../base/i18n';
import { MiddlewareOrder } from './MiddlewareOrder';

class InternalServerErrorHandler extends Middleware {
	protected order = MiddlewareOrder.InternalServerErrorHandler;
	protected route = null;
	protected action = (err: Error, req: Request, res: Response, next: NextFunction): any => {
		this.context.logError(`${err.message}: ${err.stack}`);
		res.status(StatusCodes.INTERNAL_SERVER_ERROR).send($$('org.crazydoctor.expressts.httpError.500'));
	};
}

export { InternalServerErrorHandler };