From 3b016d4876587303f6bd99484346c39def1b5a94 Mon Sep 17 00:00:00 2001 From: null Date: Mon, 6 Jul 2026 15:01:35 -0500 Subject: [PATCH] =?UTF-8?q?refactor(routes):=20version=20=E2=86=92=20throw?= =?UTF-8?q?=20pattern;=20keep=20graceful=20update-status=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /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 --- routes/version.cts | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/routes/version.cts b/routes/version.cts index 1ad04ff..f55fc35 100644 --- a/routes/version.cts +++ b/routes/version.cts @@ -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)