Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 2x 5x 2x 5x 5x 5x 3x 1x 1x 1x 4x | import { newLogger } from "@common/utils/logger.js";
import { HttpException } from "@common/exceptions/appExceptions.js";
const logger = newLogger("Middleware|errorHandler");
function logErrors(err, req, res, next) {
// Doesn't log 404 HTTPErrors
if (!(err instanceof HttpException && err.statusCode == 404)) {
logger.error("%s", err);
}
next(err);
}
function errorHandler(err, req, res, next) {
/*
* HTTP ERRORS
*/
Eif (err instanceof HttpException) {
switch (err.statusCode) {
case 404:
return next();
case 500:
return res.status(500).render("errors/500", { message: err.httpMessage, reason: err.httpReason });
default:
break;
}
}
return res.status(500).render("errors/500");
}
function notFoundHandler(req, res) {
return res.status(404).render("errors/404");
}
export { logErrors, errorHandler, notFoundHandler };
|