Files
dashcaddy/dashcaddy-api/routes/recipes/index.js
Krystie b172a21b63 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
2026-03-29 18:53:03 -07:00

56 lines
2.0 KiB
JavaScript

const express = require('express');
const deployRoutes = require('./deploy');
const manageRoutes = require('./manage');
const { NotFoundError } = require('../../errors');
module.exports = function(ctx) {
const router = express.Router();
// All recipe routes require premium license
router.use(ctx.licenseManager.requirePremium('recipes'));
// GET /api/recipes/templates — list all recipe templates
router.get('/templates', ctx.asyncHandler(async (req, res) => {
const { RECIPE_TEMPLATES, RECIPE_CATEGORIES } = require('../../recipe-templates');
const templates = Object.entries(RECIPE_TEMPLATES).map(([id, recipe]) => ({
id,
name: recipe.name,
description: recipe.description,
icon: recipe.icon,
category: recipe.category,
type: 'recipe',
difficulty: recipe.difficulty,
popularity: recipe.popularity,
componentCount: recipe.components.length,
requiredCount: recipe.components.filter(c => c.required).length,
optionalCount: recipe.components.filter(c => !c.required).length,
components: recipe.components.map(c => ({
id: c.id,
role: c.role,
required: c.required,
internal: c.internal || false,
templateRef: c.templateRef || null,
note: c.note || null
})),
setupInstructions: recipe.setupInstructions
}));
res.json({ success: true, templates, categories: RECIPE_CATEGORIES });
}, 'recipe-templates'));
// GET /api/recipes/templates/:recipeId — get single recipe template detail
router.get('/templates/:recipeId', ctx.asyncHandler(async (req, res) => {
const { RECIPE_TEMPLATES } = require('../../recipe-templates');
const recipe = RECIPE_TEMPLATES[req.params.recipeId];
if (!recipe) throw new NotFoundError(`Recipe template ${req.params.recipeId}`);
res.json({ success: true, recipe: { id: req.params.recipeId, ...recipe } });
}, 'recipe-template-detail'));
// Mount deploy and manage sub-routes
router.use(deployRoutes(ctx));
router.use(manageRoutes(ctx));
return router;
};