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
+4 -3
View File
@@ -1,5 +1,6 @@
const path = require('path');
const fs = require('fs').promises;
const logger = require('./logger');
/**
* Secure file security utilities to prevent path traversal and validate file types
@@ -174,7 +175,7 @@ async function validateFileContent(filePath, expectedMimeType) {
return true;
});
} catch (error) {
console.error('Error validating file content:', error);
logger.error('Error validating file content:', error);
return false;
}
}
@@ -239,7 +240,7 @@ function createFileUploadValidator(options = {}) {
try {
await fs.unlink(file.path);
} catch (err) {
console.error('Error removing invalid file:', err);
logger.error('Error removing invalid file:', err);
}
return res.status(400).json({
error: `File content does not match declared type: ${file.originalname}`
@@ -250,7 +251,7 @@ function createFileUploadValidator(options = {}) {
next();
} catch (error) {
console.error('File validation error:', error);
logger.error('File validation error:', error);
res.status(500).json({ error: 'File validation failed' });
}
};