refactor(routes): version → throw pattern; keep graceful update-status fallback

/history 404 → throw NotFoundError (body was already normalized); drop the
generic 500 swallow. The /update-status catch is intentional graceful
degradation (returns a valid 200 fallback) — kept.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
null 2026-07-06 15:01:35 -05:00
parent 59c2917e1d
commit 3b016d4876
1 changed files with 10 additions and 24 deletions

View File

@ -4,6 +4,7 @@ const express = require('express');
const router = express.Router();
const fs = require('fs');
const path = require('path');
const { NotFoundError } = require('../utils/apiError.cts');
const HISTORY_PATH = path.join(__dirname, '..', 'HISTORY.md');
let pkg;
@ -56,15 +57,7 @@ router.get('/', (req: Req, res: Res) => {
// GET /api/version/history
router.get('/history', (req: Req, res: Res) => {
try {
if (!fs.existsSync(HISTORY_PATH)) {
return res.status(404).json({
error: 'Release history not found',
version: pkg.version,
history: '',
updated_at: null,
});
}
if (!fs.existsSync(HISTORY_PATH)) throw NotFoundError('Release history not found');
const history = fs.readFileSync(HISTORY_PATH, 'utf8');
let updatedAt = null;
@ -74,14 +67,7 @@ router.get('/history', (req: Req, res: Res) => {
updatedAt = null;
}
res.json({
version: pkg.version,
history,
updated_at: updatedAt,
});
} catch (err) {
res.status(500).json({ error: 'Failed to read release history' });
}
res.json({ version: pkg.version, history, updated_at: updatedAt });
});
// GET /api/version/update-status — public, returns cached update check (no force-refresh)