💄Added user friendly error page instead of JSON response

This commit is contained in:
Anton SHEPILOV
2024-08-25 22:26:28 +02:00
committed by Eric Doughty-Papassideris
parent 3c156c4421
commit 7941ba2e1f
2 changed files with 219 additions and 2 deletions
@@ -1,14 +1,20 @@
import logger from '@/lib/logger';
import { NextFunction, Request, Response } from 'express';
import * as Utils from '@/utils';
import { SERVER_ORIGIN, SERVER_PREFIX } from '@config';
export default (error: Error & { status?: number }, req: Request, res: Response, next: NextFunction): void => {
try {
const status: number = error.status || 500;
const message: string = error.message || 'something went wrong';
const message: string = error.message || 'Something went wrong';
logger.error(`[${req.method}] ${req.path} >> StatusCode:: ${status}, Message:: ${message}`, error.stack);
res.status(status).json({ message });
res.status(status);
res.render('error', {
server: Utils.joinURL([SERVER_ORIGIN, SERVER_PREFIX]),
errorMessage: message,
});
} catch (error) {
next(error);
}