From e94040a8825f5b92d45530ae6dccaf327518978c Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sun, 9 Aug 2026 02:22:58 +1000 Subject: [PATCH] fix(chat): stop showing raw 501 banner for unconfigured update-check refreshUpdate() rendered the fetch error's raw message text into a visible banner on every page load, including a plain "501: Not Implemented" when chat.telegram.update_check_command is unset -- a normal "feature not configured" state, not a failure. Add updateUnavailableMessage() (chat-update-status.js) to branch on ApiError.status: 501 renders nothing (matching how Channels shows a calm "not configured" state for an unconfigured channel), any other error gets a fixed human message instead of the raw fetch text. Fixes #443 --- ui/src/chat/chat-update-status.js | 15 +++++++++++++++ ui/src/chat/chat.js | 8 +++++++- ui/test/chat-update-status.test.js | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 ui/src/chat/chat-update-status.js create mode 100644 ui/test/chat-update-status.test.js diff --git a/ui/src/chat/chat-update-status.js b/ui/src/chat/chat-update-status.js new file mode 100644 index 000000000..91099c89c --- /dev/null +++ b/ui/src/chat/chat-update-status.js @@ -0,0 +1,15 @@ +// updateUnavailableMessage decides what -- if anything -- refreshUpdate should +// show when fetching /api/chat/update fails. +// +// A 501 means the release-update-check feature simply isn't configured for +// this deployment (chat.telegram.update_check_command is unset) -- a normal +// state, the same category as an unconfigured chat channel, not a fetch +// failure. It gets no visible banner: callers should render nothing. +// +// Any other error (network failure, 500, ...) is a genuine problem and gets a +// clear, fixed human message -- never the raw fetch error text, which leaks +// implementation detail like literal HTTP status codes into the UI. +export function updateUnavailableMessage(err) { + if (err?.status === 501) return null; + return "Could not check for updates."; +} diff --git a/ui/src/chat/chat.js b/ui/src/chat/chat.js index 01e7e3752..9cd64e617 100644 --- a/ui/src/chat/chat.js +++ b/ui/src/chat/chat.js @@ -7,6 +7,7 @@ import { channelID } from "./chat-state.js"; import { retryChatTurn, resolveTurn } from "./chat-retry.js"; import { renderCommands, renderModels, renderSelectors, renderSessions } from "./chat-catalog.js"; import { renderDangerous, renderUpdate } from "./chat-panels.js"; +import { updateUnavailableMessage } from "./chat-update-status.js"; import "./chat.css"; @@ -115,7 +116,12 @@ export function chatPage() { }, }); } catch (err) { - updatePanel.replaceChildren(el("span", err.message || "Updates unavailable")); + // A 501 means this deployment hasn't configured the update-check + // feature -- a normal, quiet state (same as an unconfigured chat + // channel), not a banner. Anything else is a genuine failure and gets + // a clear message, never the raw fetch error text. + const message = updateUnavailableMessage(err); + updatePanel.replaceChildren(...(message ? [el("span", message)] : [])); } } diff --git a/ui/test/chat-update-status.test.js b/ui/test/chat-update-status.test.js new file mode 100644 index 000000000..7f0be511b --- /dev/null +++ b/ui/test/chat-update-status.test.js @@ -0,0 +1,22 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { ApiError } from "../src/base/api.js"; +import { updateUnavailableMessage } from "../src/chat/chat-update-status.js"; + +test("a 501 (feature not configured) is a quiet non-error, not a banner", () => { + assert.equal(updateUnavailableMessage(new ApiError("501: Not Implemented", 501)), null); +}); + +test("a genuine failure gets a clear human message, not the raw fetch error text", () => { + const err = new ApiError("500 Internal Server Error", 500); + const message = updateUnavailableMessage(err); + assert.ok(message); + assert.notEqual(message, err.message); +}); + +test("an error with no status (e.g. a network failure) also gets a human message", () => { + const err = new TypeError("Failed to fetch"); + const message = updateUnavailableMessage(err); + assert.ok(message); + assert.notEqual(message, err.message); +});