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
This commit is contained in:
1 parent
b56f07fe73
commit
e94040a882
3 files changed
+44
-1
No files matched your search
@@ -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.";
|
||||
}
|
||||
+7
-1
@@ -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)] : []));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
Reference in new issue
Block a user