feat(FN-1528): sanitize Kimi 404 url.not_found errors in usage screen

- Add sanitization for Kimi API 404 url.not_found error messages in usage.ts
- Replace technical error codes with user-friendly messages to avoid leaking internal API details
- Add regression test covering error sanitization with mock usage data
This commit is contained in:
gsxdsm
2026-04-10 02:57:32 -07:00
parent 174ef490e7
commit a3d70e5190
3 changed files with 73 additions and 3 deletions

View File

@@ -1482,8 +1482,16 @@ async function fetchKimiUsage(): Promise<ProviderUsage> {
if (res.status === 404) {
if (isLastEndpoint) {
// Last endpoint also returned 404 — return error
// Sanitize known endpoint-not-found errors to avoid leaking raw JSON to users.
// The "url.not_found" error indicates the usage endpoint doesn't exist for this account.
const isEndpointNotFound = res.body.includes('"error":"url.not_found"') ||
res.body.includes('"error":"url_not_found"');
usage.status = "error";
usage.error = `HTTP 404: ${res.body.slice(0, 200)}`;
if (isEndpointNotFound) {
usage.error = "Usage endpoint unavailable — Kimi coding plan may not be active on this account";
} else {
usage.error = `HTTP 404: ${res.body.slice(0, 200)}`;
}
return usage;
}
// Try next endpoint