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:
parent
59c2917e1d
commit
3b016d4876
|
|
@ -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,32 +57,17 @@ router.get('/', (req: Req, res: Res) => {
|
|||
|
||||
// GET /api/version/history
|
||||
router.get('/history', (req: Req, res: Res) => {
|
||||
if (!fs.existsSync(HISTORY_PATH)) throw NotFoundError('Release history not found');
|
||||
|
||||
const history = fs.readFileSync(HISTORY_PATH, 'utf8');
|
||||
let updatedAt = null;
|
||||
try {
|
||||
if (!fs.existsSync(HISTORY_PATH)) {
|
||||
return res.status(404).json({
|
||||
error: 'Release history not found',
|
||||
version: pkg.version,
|
||||
history: '',
|
||||
updated_at: null,
|
||||
});
|
||||
}
|
||||
|
||||
const history = fs.readFileSync(HISTORY_PATH, 'utf8');
|
||||
let updatedAt = null;
|
||||
try {
|
||||
updatedAt = fs.statSync(HISTORY_PATH).mtime.toISOString();
|
||||
} catch {
|
||||
updatedAt = null;
|
||||
}
|
||||
|
||||
res.json({
|
||||
version: pkg.version,
|
||||
history,
|
||||
updated_at: updatedAt,
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: 'Failed to read release history' });
|
||||
updatedAt = fs.statSync(HISTORY_PATH).mtime.toISOString();
|
||||
} catch {
|
||||
updatedAt = null;
|
||||
}
|
||||
|
||||
res.json({ version: pkg.version, history, updated_at: updatedAt });
|
||||
});
|
||||
|
||||
// GET /api/version/update-status — public, returns cached update check (no force-refresh)
|
||||
|
|
|
|||
Loading…
Reference in New Issue