fix: Expose error stack together with error message

This commit is contained in:
Faruk AYDIN
2023-03-25 14:01:04 +03:00
parent 8035f81f97
commit cf83c27ca0

View File

@@ -4,11 +4,16 @@ import logger from './logger';
import BaseError from '../errors/base';
// Do not remove `next` argument as the function signature will not fit for an error handler middleware
const errorHandler = (err: BaseError, req: Request, res: Response, next: NextFunction): void => {
const errorHandler = (
err: BaseError,
req: Request,
res: Response,
next: NextFunction
): void => {
if (err.message === 'Not Found') {
res.status(404).end();
} else {
logger.error(err.message);
logger.error(err.message + '\n' + err.stack);
res.status(err.statusCode || 500).send(err.message);
}
};