app: log all errors (debug)

This commit is contained in:
Alice Gaudon 2024-09-21 18:39:45 +02:00
parent b59e053cad
commit 6031d3a2e6

View File

@ -18,7 +18,7 @@ import Extendable, {MissingComponentError} from "./Extendable.js";
import {BadRequestError, HttpError, NotFoundHttpError, ServerError, ServiceUnavailableHttpError} from "./HttpError.js"; import {BadRequestError, HttpError, NotFoundHttpError, ServerError, ServiceUnavailableHttpError} from "./HttpError.js";
import {logger, loggingContextMiddleware} from "./Logger.js"; import {logger, loggingContextMiddleware} from "./Logger.js";
import SecurityError from "./SecurityError.js"; import SecurityError from "./SecurityError.js";
import {doesFileExist, Type} from "./Utils.js"; import {doesFileExist, Type, WrappingError} from "./Utils.js";
import WebSocketListener from "./WebSocketListener.js"; import WebSocketListener from "./WebSocketListener.js";
import TemplateError = nunjucks.lib.TemplateError; import TemplateError = nunjucks.lib.TemplateError;
import AppLocalsCoreComponents from "./components/core/AppLocalsCoreComponents.js"; import AppLocalsCoreComponents from "./components/core/AppLocalsCoreComponents.js";
@ -145,6 +145,11 @@ export default abstract class Application implements Extendable<ApplicationCompo
app.use((err: unknown, req: Request, res: Response, next: NextFunction) => { app.use((err: unknown, req: Request, res: Response, next: NextFunction) => {
if (res.headersSent) return next(err); if (res.headersSent) return next(err);
logger.debug(err);
if (err instanceof WrappingError) {
logger.debug("-> Caused by", err.cause);
}
// Transform single validation errors into a validation bag for convenience // Transform single validation errors into a validation bag for convenience
if (err instanceof ValidationError) { if (err instanceof ValidationError) {
const bag = new ValidationBag(); const bag = new ValidationBag();