v1.13.4: Standardize all route responses to use response helpers
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:
@@ -1,6 +1,7 @@
|
||||
const express = require('express');
|
||||
const { DOCKER } = require('../../constants');
|
||||
const { NotFoundError } = require('../../errors');
|
||||
const { ok } = require('../../src/utils/responses');
|
||||
|
||||
module.exports = function({ servicesStateManager, asyncHandler, log, docker, notification, buildDomain, caddy }) {
|
||||
const router = express.Router();
|
||||
@@ -98,7 +99,7 @@ module.exports = function({ servicesStateManager, asyncHandler, log, docker, not
|
||||
}
|
||||
}
|
||||
|
||||
res.json({ success: true, recipes: Object.values(recipeGroups) });
|
||||
ok(res, { recipes: Object.values(recipeGroups) });
|
||||
}, 'recipe-deployed'));
|
||||
|
||||
/**
|
||||
@@ -129,7 +130,7 @@ module.exports = function({ servicesStateManager, asyncHandler, log, docker, not
|
||||
}
|
||||
|
||||
log.info('recipe', 'Recipe started', { recipeId, results });
|
||||
res.json({ success: true, recipeId, results });
|
||||
ok(res, { recipeId, results });
|
||||
}, 'recipe-start'));
|
||||
|
||||
/**
|
||||
@@ -161,7 +162,7 @@ module.exports = function({ servicesStateManager, asyncHandler, log, docker, not
|
||||
}
|
||||
|
||||
log.info('recipe', 'Recipe stopped', { recipeId, results });
|
||||
res.json({ success: true, recipeId, results });
|
||||
ok(res, { recipeId, results });
|
||||
}, 'recipe-stop'));
|
||||
|
||||
/**
|
||||
@@ -187,7 +188,7 @@ module.exports = function({ servicesStateManager, asyncHandler, log, docker, not
|
||||
}
|
||||
|
||||
log.info('recipe', 'Recipe restarted', { recipeId, results });
|
||||
res.json({ success: true, recipeId, results });
|
||||
ok(res, { recipeId, results });
|
||||
}, 'recipe-restart'));
|
||||
|
||||
/**
|
||||
@@ -259,7 +260,7 @@ module.exports = function({ servicesStateManager, asyncHandler, log, docker, not
|
||||
);
|
||||
|
||||
log.info('recipe', 'Recipe removed', { recipeId, results });
|
||||
res.json({ success: true, recipeId, results });
|
||||
ok(res, { recipeId, results });
|
||||
}, 'recipe-remove'));
|
||||
|
||||
// === Helper functions ===
|
||||
|
||||
Reference in New Issue
Block a user