Migrate 25 route files to throw-based error handling
Converted routes: - All auth routes (totp.js, keys.js, sso-gate.js) - Recipe deployment routes (deploy.js, manage.js, index.js) - App deployment routes - Config routes (assets, backup, settings) - ARR routes (config, credentials) - Infrastructure routes (dns, services, sites, logs) - Additional routes (browse, ca, health, license, notifications, tailscale, updates) Changes: - Replaced ctx.errorResponse() with throw statements - Replaced errorResponse() with throw statements - Added proper error imports to each file - 400 errors → ValidationError - 401 errors → AuthenticationError - 403 errors → ForbiddenError - 404 errors → NotFoundError - 409 errors → ConflictError - 500 errors → Handled by middleware Result: 25 files migrated, ~150 error responses standardized
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const express = require('express');
|
||||
const { paginate, parsePaginationParams } = require('../pagination');
|
||||
const { ValidationError } = require('../errors');
|
||||
|
||||
module.exports = function(ctx) {
|
||||
const router = express.Router();
|
||||
@@ -53,7 +54,7 @@ module.exports = function(ctx) {
|
||||
router.post('/updates/schedule/:containerId', ctx.asyncHandler(async (req, res) => {
|
||||
const { scheduledTime } = req.body;
|
||||
if (!scheduledTime) {
|
||||
return ctx.errorResponse(res, 400, 'scheduledTime is required');
|
||||
throw new ValidationError('scheduledTime is required');
|
||||
}
|
||||
ctx.updateManager.scheduleUpdate(req.params.containerId, scheduledTime);
|
||||
res.json({ success: true, message: 'Update scheduled', scheduledTime });
|
||||
@@ -116,7 +117,7 @@ module.exports = function(ctx) {
|
||||
// Rollback to a previous version
|
||||
router.post('/system/rollback', ctx.asyncHandler(async (req, res) => {
|
||||
const { version } = req.body;
|
||||
if (!version) return ctx.errorResponse(res, 400, 'version is required');
|
||||
if (!version) throw new ValidationError('version is required');
|
||||
ctx.selfUpdater.rollbackToVersion(version).catch(err => {
|
||||
ctx.logError('self-rollback', err);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user