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,4 +1,5 @@
|
||||
const express = require('express');
|
||||
const { ValidationError } = require('../../errors');
|
||||
const crypto = require('crypto');
|
||||
const { DOCKER } = require('../../constants');
|
||||
|
||||
@@ -16,7 +17,7 @@ module.exports = function(ctx) {
|
||||
const { RECIPE_TEMPLATES } = require('../../recipe-templates');
|
||||
|
||||
const recipe = RECIPE_TEMPLATES[recipeId];
|
||||
if (!recipe) return ctx.errorResponse(res, 400, 'Invalid recipe template');
|
||||
if (!recipe) throw new ValidationError('Invalid recipe template', 'recipeId');
|
||||
|
||||
ctx.log.info('recipe', 'Starting recipe deployment', { recipeId, name: recipe.name });
|
||||
|
||||
@@ -165,7 +166,7 @@ module.exports = function(ctx) {
|
||||
`Failed to deploy **${recipe.name}**: ${error.message}`, 'error'
|
||||
);
|
||||
|
||||
ctx.errorResponse(res, 500, error.message);
|
||||
// Error automatically handled by middleware
|
||||
}
|
||||
}, 'recipe-deploy'));
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const express = require('express');
|
||||
const deployRoutes = require('./deploy');
|
||||
const manageRoutes = require('./manage');
|
||||
const { NotFoundError } = require('../../errors');
|
||||
|
||||
module.exports = function(ctx) {
|
||||
const router = express.Router();
|
||||
@@ -41,7 +42,7 @@ module.exports = function(ctx) {
|
||||
router.get('/templates/:recipeId', ctx.asyncHandler(async (req, res) => {
|
||||
const { RECIPE_TEMPLATES } = require('../../recipe-templates');
|
||||
const recipe = RECIPE_TEMPLATES[req.params.recipeId];
|
||||
if (!recipe) return ctx.errorResponse(res, 404, 'Recipe template not found');
|
||||
if (!recipe) throw new NotFoundError(`Recipe template ${req.params.recipeId}`);
|
||||
|
||||
res.json({ success: true, recipe: { id: req.params.recipeId, ...recipe } });
|
||||
}, 'recipe-template-detail'));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const express = require('express');
|
||||
const { DOCKER } = require('../../constants');
|
||||
const { NotFoundError } = require('../../errors');
|
||||
|
||||
module.exports = function(ctx) {
|
||||
const router = express.Router();
|
||||
@@ -96,7 +97,7 @@ module.exports = function(ctx) {
|
||||
const containers = await findRecipeContainers(recipeId);
|
||||
|
||||
if (containers.length === 0) {
|
||||
return ctx.errorResponse(res, 404, 'No containers found for this recipe');
|
||||
throw new NotFoundError('Containers for recipe');
|
||||
}
|
||||
|
||||
const results = [];
|
||||
@@ -127,7 +128,7 @@ module.exports = function(ctx) {
|
||||
const containers = await findRecipeContainers(recipeId);
|
||||
|
||||
if (containers.length === 0) {
|
||||
return ctx.errorResponse(res, 404, 'No containers found for this recipe');
|
||||
throw new NotFoundError('Containers for recipe');
|
||||
}
|
||||
|
||||
const results = [];
|
||||
@@ -159,7 +160,7 @@ module.exports = function(ctx) {
|
||||
const containers = await findRecipeContainers(recipeId);
|
||||
|
||||
if (containers.length === 0) {
|
||||
return ctx.errorResponse(res, 404, 'No containers found for this recipe');
|
||||
throw new NotFoundError('Containers for recipe');
|
||||
}
|
||||
|
||||
const results = [];
|
||||
@@ -185,7 +186,7 @@ module.exports = function(ctx) {
|
||||
const containers = await findRecipeContainers(recipeId);
|
||||
|
||||
if (containers.length === 0) {
|
||||
return ctx.errorResponse(res, 404, 'No containers found for this recipe');
|
||||
throw new NotFoundError('Containers for recipe');
|
||||
}
|
||||
|
||||
ctx.log.info('recipe', 'Removing recipe', { recipeId, containerCount: containers.length });
|
||||
|
||||
Reference in New Issue
Block a user