refactor(backend): standardize error responses, logging, pagination

- errorResponse(res, error, status, publicMessage) in routeHelpers,
  wired into 125 catch blocks across 10 route files; wire format
  ({ error: <string> }) unchanged byte-for-byte
- Replace remaining console.* with logger across src (178 sites);
  3 intentional console sites kept (install boot, unbound .catch ref)
- Adopt getPagination in 6 routes where semantics match exactly
This commit is contained in:
Paul Nothaft
2026-07-03 07:49:45 +02:00
parent d44ead41c5
commit 6eb46d8c31
41 changed files with 372 additions and 482 deletions
+3 -2
View File
@@ -1,6 +1,7 @@
const path = require('path');
const express = require('express');
const { safePathJoin, isPathSafe } = require('../utils/fileSecurityUtils');
const logger = require('../utils/logger');
/**
* Create a secure static file serving middleware that prevents path traversal attacks
@@ -17,7 +18,7 @@ function secureStatic(basePath, options = {}) {
// Validate the path doesn't contain dangerous patterns
if (!isPathSafe(requestedPath)) {
console.warn(`Potential path traversal attempt blocked: ${requestedPath}`);
logger.warn(`Potential path traversal attempt blocked: ${requestedPath}`);
return res.status(403).json({ error: 'Access denied' });
}
@@ -52,7 +53,7 @@ function secureStatic(basePath, options = {}) {
return staticMiddleware(req, res, next);
} catch (error) {
// Path traversal detected
console.error(`Path traversal blocked: ${requestedPath}`, error.message);
logger.error(`Path traversal blocked: ${requestedPath}`, error.message);
return res.status(403).json({ error: 'Access denied' });
}
};