fix(mcp): improve error message internationalization

- Add translateMcpBackendError utility to map backend errors to i18n keys
- Update error handling in McpPanel, McpFormModal, and McpWizardModal
- Internationalize stdio/http type selectors in Wizard
- Implement three-tier fallback strategy: translation → raw error → default message
- No backend changes required, fully frontend-based i18n implementation
This commit is contained in:
Jason
2025-10-11 16:20:12 +08:00
parent c2b27a4949
commit ea7080a42e
7 changed files with 90 additions and 13 deletions

View File

@@ -5,7 +5,10 @@ import { McpServer } from "../../types";
import McpListItem from "./McpListItem";
import McpFormModal from "./McpFormModal";
import { ConfirmDialog } from "../ConfirmDialog";
import { extractErrorMessage } from "../../utils/errorUtils";
import {
extractErrorMessage,
translateMcpBackendError,
} from "../../utils/errorUtils";
// 预设相关逻辑已迁移到“新增 MCP”面板列表此处无需引用
import { buttonStyles } from "../../lib/styles";
import { AppType } from "../../lib/tauri-api";
@@ -89,10 +92,11 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify, appType }) => {
// 失败时回滚
setServers(previousServers);
const detail = extractErrorMessage(e);
const mapped = translateMcpBackendError(detail, t);
onNotify?.(
detail || t("mcp.error.saveFailed"),
mapped || detail || t("mcp.error.saveFailed"),
"error",
detail ? 6000 : 5000,
mapped || detail ? 6000 : 5000,
);
}
};
@@ -120,10 +124,11 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify, appType }) => {
onNotify?.(t("mcp.msg.deleted"), "success", 1500);
} catch (e: any) {
const detail = extractErrorMessage(e);
const mapped = translateMcpBackendError(detail, t);
onNotify?.(
detail || t("mcp.error.deleteFailed"),
mapped || detail || t("mcp.error.deleteFailed"),
"error",
detail ? 6000 : 5000,
mapped || detail ? 6000 : 5000,
);
}
},
@@ -139,10 +144,11 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify, appType }) => {
onNotify?.(t("mcp.msg.saved"), "success", 1500);
} catch (e: any) {
const detail = extractErrorMessage(e);
const mapped = translateMcpBackendError(detail, t);
onNotify?.(
detail || t("mcp.error.saveFailed"),
mapped || detail || t("mcp.error.saveFailed"),
"error",
detail ? 6000 : 5000,
mapped || detail ? 6000 : 5000,
);
// 继续抛出错误,让表单层可以给到直观反馈(避免被更高层遮挡)
throw e;