v1.13.4: Standardize all route responses to use response helpers
CI / Test & Lint (push) Has been cancelled
CI / Security audit (push) Has been cancelled

Convert ~160 raw res.json()/res.status().json() calls across 32+ files
to use centralized helpers from src/utils/responses.js (ok, errorResponse,
successMessage, notFound, validationError, forbidden, unauthorized, conflict).

No behavior changes — response shapes are identical. Future schema changes
(e.g., requestId envelope) only need to update one module.

Fix error vs errorResponse signature mismatch in routes/health.js CA cert
endpoint where error(res, message, statusCode) was being called with
errorResponse(res, statusCode, message, extras) argument order.

Files changed: middleware.js, csrf-protection.js, error-handler.js,
license-manager.js, src/app.js, and 27 route files.

Test suite: 755 pass / 4 pre-existing failures (services credential tests).
This commit is contained in:
Hermes
2026-06-11 00:48:13 -07:00
parent 2d394d882d
commit 53680c4c74
40 changed files with 251 additions and 275 deletions
+11 -13
View File
@@ -3,6 +3,7 @@ const { validateURL, validateToken } = require('../input-validator');
const validatorLib = require('validator');
const { paginate, parsePaginationParams } = require('../pagination');
const { ValidationError } = require('../errors');
const { ok, successMessage } = require('../src/utils/responses');
/**
* Notifications route factory
@@ -44,7 +45,7 @@ module.exports = function({ notification, asyncHandler }) {
events: notificationConfig.events,
healthCheck: notificationConfig.healthCheck
};
res.json({ success: true, config: safeConfig });
ok(res, { config: safeConfig });
}, 'notifications-config-get'));
// POST /config — Update notification configuration
@@ -150,7 +151,7 @@ module.exports = function({ notification, asyncHandler }) {
}
await notification.saveConfig();
res.json({ success: true, message: 'Notification config updated' });
successMessage(res, 'Notification config updated');
}, 'notifications-config-update'));
// POST /test — Test notification delivery
@@ -176,11 +177,11 @@ module.exports = function({ notification, asyncHandler }) {
default:
throw new ValidationError('Unknown provider');
}
res.json({ success: result.success, provider, error: result.error });
ok(res, { success: result.success, provider, error: result.error });
} else {
// Test all enabled providers
const result = await notification.send('test', 'Test Notification', 'This is a test notification from DashCaddy.', 'info');
res.json({ success: true, ...result });
ok(res, { success: true, ...result });
}
}, 'notifications-test'));
@@ -190,11 +191,10 @@ module.exports = function({ notification, asyncHandler }) {
const paginationParams = parsePaginationParams(req.query);
if (paginationParams) {
const result = paginate(notificationHistory, paginationParams);
res.json({ success: true, history: result.data, total: notificationHistory.length, pagination: result.pagination });
ok(res, { history: result.data, total: notificationHistory.length, pagination: result.pagination });
} else {
const limit = parseInt(req.query.limit) || 50;
res.json({
success: true,
ok(res, {
history: notificationHistory.slice(0, limit),
total: notificationHistory.length
});
@@ -204,15 +204,14 @@ module.exports = function({ notification, asyncHandler }) {
// DELETE /history — Clear notification history
router.delete('/history', asyncHandler(async (req, res) => {
notification.clearHistory();
res.json({ success: true, message: 'Notification history cleared' });
successMessage(res, 'Notification history cleared');
}, 'notifications-history-clear'));
// POST /health-check — Manually trigger health check
router.post('/health-check', asyncHandler(async (req, res) => {
await notification.checkHealth();
const notificationConfig = notification.getConfig();
res.json({
success: true,
ok(res, {
lastCheck: notificationConfig.healthCheck.lastCheck,
containersMonitored: Object.keys(notification.getHealthState()).length
});
@@ -223,8 +222,7 @@ module.exports = function({ notification, asyncHandler }) {
const notificationConfig = notification.getConfig();
const providers = notificationConfig.providers || {};
res.json({
success: true,
ok(res, {
enabled: notificationConfig.enabled,
providers: {
discord: providers.discord?.enabled && !!providers.discord?.webhookUrl,
@@ -252,7 +250,7 @@ module.exports = function({ notification, asyncHandler }) {
// Use 'test' as the event for manual sends
const result = await notification.send(event, data || {}, type || 'info');
res.json({
ok(res, {
success: result.success,
event,
results: result.results