🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
♻️ refactor(error): export error types rendered with dedicated cards (#19916)
YuTengjing980f10fc694e
diff --git a/locales/en-US/error.json b/locales/en-US/error.jsonindex d13bb1416d8..338011563da 100644--- a/locales/en-US/error.json+++ b/locales/en-US/error.json@@ -2,6 +2,9 @@"asyncState.desc": "Something went wrong while loading. Please try again.","asyncState.metricLabel": "Failed to load","asyncState.title": "Failed to load",+ "chatRequestBlocked.contactSupport": "Contact support",+ "chatRequestBlocked.description": "This request was blocked by our security checks. If you think this is a mistake, contact support to restore access.",+ "chatRequestBlocked.title": "Request blocked","error.backHome": "Back to Home","error.desc": "Give it a try later, or go back to the known world.","error.retry": "Reload",diff --git a/locales/zh-CN/error.json b/locales/zh-CN/error.jsonindex 5eea396bfe8..7a40b7dd020 100644--- a/locales/zh-CN/error.json+++ b/locales/zh-CN/error.json@@ -2,6 +2,9 @@"asyncState.desc": "加载时出了点问题,请重试。","asyncState.metricLabel": "加载失败","asyncState.title": "加载失败",+ "chatRequestBlocked.contactSupport": "联系客服",+ "chatRequestBlocked.description": "此请求被安全检查拦截。如果你认为这是误判,请联系客服申请解封。",+ "chatRequestBlocked.title": "请求已被拦截","error.backHome": "返回首页","error.desc": "页面暂时不可用。你可以返回首页,或稍后重试(你的设置不会因此丢失)","error.retry": "重新加载",diff --git a/packages/locales/src/default/error.ts b/packages/locales/src/default/error.tsindex 61bd5c743b7..5e8b712b5e2 100644--- a/packages/locales/src/default/error.ts+++ b/packages/locales/src/default/error.ts@@ -2,6 +2,10 @@ export default {'asyncState.desc': 'Something went wrong while loading. Please try again.','asyncState.metricLabel': 'Failed to load','asyncState.title': 'Failed to load',+ 'chatRequestBlocked.contactSupport': 'Contact support',+ 'chatRequestBlocked.description':+ 'This request was blocked by our security checks. If you think this is a mistake, contact support to restore access.',+ 'chatRequestBlocked.title': 'Request blocked','saveState.retry': 'Retry','saveState.saveFailed': 'Failed to save your changes. Please try again.','error.backHome': 'Back to Home',diff --git a/src/features/Conversation/Error/dedicatedErrorCards.ts b/src/features/Conversation/Error/dedicatedErrorCards.tsnew file mode 100644index 00000000000..e694a4c9070--- /dev/null+++ b/src/features/Conversation/Error/dedicatedErrorCards.ts@@ -0,0 +1,31 @@+import { AgentRuntimeErrorType } from '@lobechat/model-runtime';+import { ChatErrorType } from '@lobechat/types';++/**+ * Error types that `ErrorMessageExtra` renders with a dedicated card instead of the+ * generic message / trace-id fallback. The renderer's switch is type-checked against+ * this list in both directions, so a new dedicated card must be added here.+ *+ * Business overrides can key a `Record<DedicatedErrorCardType, ...>` off this list to+ * make an explicit per-type decision; a new entry then fails their type check until+ * they decide how to handle it.+ */+export const DEDICATED_ERROR_CARD_TYPES = [+ ChatErrorType.FreePlanLimit,+ ChatErrorType.SubscriptionPlanLimit,+ ChatErrorType.InsufficientBudgetForModel,+ ChatErrorType.LobeHubModelDeprecated,+ AgentRuntimeErrorType.QuotaLimitReached,+ AgentRuntimeErrorType.RateLimitExceeded,+ AgentRuntimeErrorType.OllamaServiceUnavailable,+ AgentRuntimeErrorType.OllamaBizError,+ AgentRuntimeErrorType.ExceededContextWindow,+ AgentRuntimeErrorType.NoOpenAIAPIKey,+] as const;++export type DedicatedErrorCardType = (typeof DEDICATED_ERROR_CARD_TYPES)[number];++const DEDICATED_ERROR_CARD_TYPE_SET = new Set<unknown>(DEDICATED_ERROR_CARD_TYPES);++export const isDedicatedErrorCardType = (type: unknown): type is DedicatedErrorCardType =>+ DEDICATED_ERROR_CARD_TYPE_SET.has(type);diff --git a/src/features/Conversation/Error/index.tsx b/src/features/Conversation/Error/index.tsxindex 9b0a79e9834..8905c1dce68 100644--- a/src/features/Conversation/Error/index.tsx+++ b/src/features/Conversation/Error/index.tsx@@ -35,6 +35,7 @@ import { serverConfigSelectors, useServerConfigStore } from '@/store/serverConfiimport { getRuntimeErrorMessage } from '@/utils/locale/runtimeErrorMessage';import ChatInvalidAPIKey from './ChatInvalidApiKey';+import { type DedicatedErrorCardType, isDedicatedErrorCardType } from './dedicatedErrorCards';import { isHeterogeneousAgentStatusGuideError } from './heterogeneous';import { useHeterogeneousAutoRetry } from './useHeterogeneousAutoRetry';@@ -471,57 +472,69 @@ const ErrorMessageExtra = memo<ErrorExtraProps>(if (enableBusinessFeatures && businessChatErrorMessageExtra)return businessChatErrorMessageExtra;- switch (error?.type) {- // Lightweight fallbacks for cloud billing errors, used in builds without a- // business override (e.g. desktop). The business hook above takes- // precedence when installed.- case ChatErrorType.FreePlanLimit:- case ChatErrorType.SubscriptionPlanLimit:- case ChatErrorType.InsufficientBudgetForModel: {- if (enableBusinessFeatures)+ /**+ * Typed against `DEDICATED_ERROR_CARD_TYPES`: a missing case fails the `never` check+ * and a case outside the list fails as "not comparable", so the exported list always+ * matches what this renderer customizes.+ */+ const renderDedicatedCard = (type: DedicatedErrorCardType) => {+ switch (type) {+ // Lightweight fallbacks for cloud billing errors, used in builds without a+ // business override (e.g. desktop). The business hook above takes+ // precedence when installed.+ case ChatErrorType.FreePlanLimit:+ case ChatErrorType.SubscriptionPlanLimit:+ case ChatErrorType.InsufficientBudgetForModel: {+ if (!enableBusinessFeatures) return;return (<PlanLimitCarderrorBody={error?.body}- errorType={error?.type}+ errorType={type}onRetry={handleRetryAgentMessage}/>);- break;- }+ }- case ChatErrorType.LobeHubModelDeprecated: {- if (enableBusinessFeatures)+ case ChatErrorType.LobeHubModelDeprecated: {+ if (!enableBusinessFeatures) return;return <DeprecatedModelError requestedModel={error?.body?.requestedModel} />;- break;- }+ }- case AgentRuntimeErrorType.QuotaLimitReached:- case AgentRuntimeErrorType.RateLimitExceeded: {- if (enableBusinessFeatures)+ case AgentRuntimeErrorType.QuotaLimitReached:+ case AgentRuntimeErrorType.RateLimitExceeded: {+ if (!enableBusinessFeatures) return;return (<QuotaLimitError id={data.id} onRetry={canRetry ? handleManualRetry : undefined} />);- break;- }+ }- case AgentRuntimeErrorType.OllamaServiceUnavailable: {- return <OllamaSetupGuide id={data.id} />;- }+ case AgentRuntimeErrorType.OllamaServiceUnavailable: {+ return <OllamaSetupGuide id={data.id} />;+ }- case AgentRuntimeErrorType.OllamaBizError: {- return <OllamaBizError {...data} />;- }+ case AgentRuntimeErrorType.OllamaBizError: {+ return <OllamaBizError {...data} />;+ }- case AgentRuntimeErrorType.ExceededContextWindow: {- return <ExceededContextWindowError id={data.id} />;- }+ case AgentRuntimeErrorType.ExceededContextWindow: {+ return <ExceededContextWindowError id={data.id} />;+ }- case AgentRuntimeErrorType.NoOpenAIAPIKey: {- {+ case AgentRuntimeErrorType.NoOpenAIAPIKey: {return <ChatInvalidAPIKey id={data.id} provider={data.error?.body?.provider} />;}++ default: {+ const unhandled: never = type;+ return unhandled;+ }}- }+ };++ const dedicatedCard = isDedicatedErrorCardType(error?.type)+ ? renderDedicatedCard(error.type)+ : undefined;+ if (dedicatedCard) return dedicatedCard;if (error?.type?.toString().includes('Invalid')) {return <ChatInvalidAPIKey id={data.id} provider={data.error?.body?.provider} />;