Skip to content

fix: system chat user token quota - #7830

Merged
fit2cloudwxx merged 1 commit into
v3from
pr@v3@fix_systemChatUserTokenQuota
Nov 11, 2026
Merged

fit2cloudwxx merged 1 commit into
v3from
pr@v3@fix_systemChatUserTokenQuota

Conversation

@shaohuzhang1

@shaohuzhang1 shaohuzhang1 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

【【门户】用户配额用尽后对话,接口已返回了配额用尽提醒,但是前端没有显示】
https://www.tapd.cn/tapd_fe/45245355/bug/detail/1145245355001079171

if (!tokenQuota) return '0 / 不限'
const used = formatTokenNumber(tokenQuota.used_tokens)
if (tokenQuota.quota_type === QUOTA_TYPE.UNLIMITED) return `${used} / 不限`
return `${used} / ${formatTokenNumber(tokenQuota.token_limit)}`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue is semantic, not syntactic:

  • Missing quota data is being treated as “0 / 不限” (0 / Unlimited). !tokenQuota can mean the data is still loading, failed to load, or is genuinely absent. Rendering “0 / 不限” can falsely tell users they have unlimited quota and hide an error/loading state. Safer to keep '-', use a loading/error placeholder, or only return '0 / 不限' if the business rule explicitly defines “no quota object” as “zero usage, unlimited.”

  • Hardcoded localized text: '不限' is repeated. If the app supports i18n, use a translation key/constant instead. At minimum, extract a constant to avoid duplication.

  • Add tests for:

    • tokenQuota undefined
    • unlimited quota with used_tokens > 0
    • limited quota
    • possibly null at runtime if the API can return it

Suggested safer version:

const UNLIMITED_LABEL = '不限'

function formatQuotaUsage(tokenQuota?: ChatUser['token_quota']) {
  if (!tokenQuota) return '-' // or a loading/error placeholder

  const used = formatTokenNumber(tokenQuota.used_tokens)

  if (tokenQuota.quota_type === QUOTA_TYPE.UNLIMITED) {
    return `${used} / ${UNLIMITED_LABEL}`
  }

  return `${used} / ${formatTokenNumber(tokenQuota.token_limit)}`
}

If the new behavior is intentional, add a comment explaining that missing quota data means “0 used / unlimited,” and ensure callers only pass undefined in that specific case rather than during loading or errors.

@fit2cloudwxx
fit2cloudwxx merged commit b6dd7f7 into v3 Nov 11, 2026
3 of 4 checks passed
@fit2cloudwxx
fit2cloudwxx deleted the pr@v3@fix_systemChatUserTokenQuota branch November 11, 2026 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants