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
+4 -15
View File
@@ -7,7 +7,7 @@ const { exists } = require('../fs-helpers');
const { paginate, parsePaginationParams } = require('../pagination');
const platformPaths = require('../platform-paths');
const { resolveServiceUrl } = require('../url-resolver');
const { success, error: errorResponse } = require('../src/utils/responses');
const { success, error: errorResponse, errorResponse: sendError, ok, notFound } = require('../src/utils/responses');
const { ValidationError } = require('../errors');
/**
@@ -273,12 +273,7 @@ module.exports = function({
try {
// Check if certificate exists
if (!await exists(rootCertPath)) {
return res.status(404).json({
success: false,
error: 'Root CA certificate not found',
caStatus: 'error',
daysUntilExpiration: null
});
return sendError(res, 404, 'Root CA certificate not found', { caStatus: 'error', daysUntilExpiration: null });
}
const dates = execSync(`openssl x509 -in "${rootCertPath}" -noout -dates`).toString();
@@ -304,8 +299,7 @@ module.exports = function({
message = `CA certificate expires in ${daysUntilExpiration} days`;
}
res.json({
success: true,
ok(res, {
caStatus,
message,
daysUntilExpiration,
@@ -313,12 +307,7 @@ module.exports = function({
});
} catch (error) {
await logError('GET /api/health/ca', error);
res.status(500).json({
success: false,
error: error.message,
caStatus: 'error',
daysUntilExpiration: null
});
sendError(res, 500, error.message, { caStatus: 'error', daysUntilExpiration: null });
}
}, 'health-ca'));