fix: prevent duplicate channel action toasts#5015
Conversation
WalkthroughThis PR centralizes channel API request configuration and error handling to eliminate duplicate error toasts. It introduces typed request control flags ( ChangesCentralized Channel API Error Handling & Request Configuration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/default/src/lib/api.ts`:
- Around line 19-20: Replace the default i18next import with the non-React named
import (import { t } from 'i18next') at the top of the module and convert all
user-facing fallback strings in this file to use t(...) instead of hard-coded
text; specifically replace literals like "Request failed" and "Request error"
(and any other fallbacks in the error-building functions such as
normalizeErrorMessage / getErrorMessage / handleApiError or module-level default
message constants between lines ~80-117) with i18n keys (e.g.
t('errors.requestFailed'), t('errors.requestError')) so every user-visible
message uses t() and follows the repo standard import.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6d55fbb4-16bc-4eed-a25d-ed786d551295
📒 Files selected for processing (7)
web/default/src/features/channels/api.tsweb/default/src/features/channels/components/dialogs/multi-key-manage-dialog.tsxweb/default/src/features/channels/components/dialogs/ollama-models-dialog.tsxweb/default/src/features/channels/components/drawers/channel-mutate-drawer.tsxweb/default/src/features/channels/hooks/use-channel-upstream-updates.tsweb/default/src/features/channels/lib/channel-actions.tsweb/default/src/lib/api.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
web/default/src/lib/api.ts (1)
63-72:⚠️ Potential issue | 🟠 Major | ⚡ Quick winInclude the per-request error flags in the GET dedupe identity.
The dedupe key still only uses
url+params, so two concurrentapi.getcalls with differentskipBusinessError/skipErrorHandlervalues collapse onto one promise. That makes the first caller’s config decide whether the interceptor toasts, which can suppress or reintroduce duplicate channel toasts depending on call order.Suggested fix
- const params = config.params ? JSON.stringify(config.params) : '{}' - const key = `${url}?${params}` + const params = config.params ? JSON.stringify(config.params) : '{}' + const key = JSON.stringify({ + url, + params, + skipBusinessError: !!config.skipBusinessError, + skipErrorHandler: !!config.skipErrorHandler, + })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/default/src/lib/api.ts` around lines 63 - 72, The dedupe key used by inFlightGet only includes url and params so concurrent api.get calls with different per-request flags (skipBusinessError / skipErrorHandler) collapse; update the key generation (where params and key are built for inFlightGet) to incorporate those boolean flags from the config (e.g., include config.skipBusinessError and config.skipErrorHandler in the stringified identity) so that inFlightGet.lookup, set, and deletion around originalGet preserve distinct promises for different flag combinations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@web/default/src/lib/api.ts`:
- Around line 63-72: The dedupe key used by inFlightGet only includes url and
params so concurrent api.get calls with different per-request flags
(skipBusinessError / skipErrorHandler) collapse; update the key generation
(where params and key are built for inFlightGet) to incorporate those boolean
flags from the config (e.g., include config.skipBusinessError and
config.skipErrorHandler in the stringified identity) so that inFlightGet.lookup,
set, and deletion around originalGet preserve distinct promises for different
flag combinations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fc277ffe-e6b3-4d8e-a631-13a85502d4c5
📒 Files selected for processing (1)
web/default/src/lib/api.ts
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
修复default 前端渠道管理操作失败时 toast 重复弹出。根因是
api.ts全局响应拦截器会对业务错误/HTTP 错误统一提示,而渠道管理的操作层也会根据返回结果自行提示,导致同一次失败出现两条错误通知。本次将渠道管理的用户动作请求统一标记为由调用方处理错误,跳过全局错误 toast,并补齐对应调用点的本地失败处理。同时保留 401 登录态清理逻辑,避免跳过全局提示后影响认证状态一致性。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
iShot_2026-05-21_16.14.15.mp4
Summary by CodeRabbit
Bug Fixes
Refactor