From a3768dae97da269eea33030d120bd20736c41d15 Mon Sep 17 00:00:00 2001 From: t0ng7u Date: Fri, 11 Jul 2025 23:37:47 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20enable=20fetching=20model?= =?UTF-8?q?=20list=20in=20creation=20mode=20&=20refine=20toast-based=20err?= =?UTF-8?q?or=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary • **EditChannel.js** – Displays “Fetch Model List” button for both *create* and *edit* modes (removed `isEdit` guard). – Unified model selector placeholder to “Please choose supported models”. – Added null-safety checks when parsing Axios responses. – Sends requests with `{ skipErrorHandler: true }`, preventing generic *500 Internal Server Error* toasts and relying on context-specific messages instead. • **helpers/api.js** – Introduced `skipErrorHandler` flag in the Axios response interceptor. If present, global `showError` is bypassed, giving callers full control over user-facing notifications. – Ensures `Promise.reject(error)` is returned for proper error propagation. Why Channel creators now enjoy the same convenience as editors when importing upstream model lists. Meanwhile, suppressing redundant toasts removes confusion caused by simultaneous custom and generic error messages. --- web/src/helpers/api.js | 7 +++++- web/src/i18n/locales/en.json | 1 - web/src/pages/Channel/EditChannel.js | 32 +++++++++++++++------------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/web/src/helpers/api.js b/web/src/helpers/api.js index e00a5bdb..0646f77b 100644 --- a/web/src/helpers/api.js +++ b/web/src/helpers/api.js @@ -59,7 +59,12 @@ export function updateAPI() { API.interceptors.response.use( (response) => response, (error) => { + // 如果请求配置中显式要求跳过全局错误处理,则不弹出默认错误提示 + if (error.config && error.config.skipErrorHandler) { + return Promise.reject(error); + } showError(error); + return Promise.reject(error); }, ); @@ -83,7 +88,7 @@ export const buildApiPayload = (messages, systemPrompt, inputs, parameterEnabled const payload = { model: inputs.model, messages: processedMessages, - group: inputs.group, + group: inputs.group, stream: inputs.stream, }; diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index 5c9e2fcc..29bf9ac6 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -1754,7 +1754,6 @@ "批量创建时会在名称后自动添加随机后缀": "When creating in batches, a random suffix will be automatically added to the name", "额度必须大于0": "Quota must be greater than 0", "生成数量必须大于0": "Generation quantity must be greater than 0", - "创建后可在编辑渠道时获取上游模型列表": "After creation, you can get the upstream model list when editing the channel", "可用端点类型": "Supported endpoint types", "未登录,使用默认分组倍率:": "Not logged in, using default group ratio: ", "该服务器地址将影响支付回调地址以及默认首页展示的地址,请确保正确配置": "This server address will affect the payment callback address and the address displayed on the default homepage, please ensure correct configuration" diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index f53b4abb..024c15f6 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -238,9 +238,9 @@ const EditChannel = (props) => { let err = false; if (isEdit) { - // 如果是编辑模式,使用已有的channel id获取模型列表 - const res = await API.get('/api/channel/fetch_models/' + channelId); - if (res.data && res.data.success) { + // 如果是编辑模式,使用已有的 channelId 获取模型列表 + const res = await API.get('/api/channel/fetch_models/' + channelId, { skipErrorHandler: true }); + if (res && res.data && res.data.success) { models.push(...res.data.data); } else { err = true; @@ -252,13 +252,17 @@ const EditChannel = (props) => { err = true; } else { try { - const res = await API.post('/api/channel/fetch_models', { - base_url: inputs['base_url'], - type: inputs['type'], - key: inputs['key'], - }); + const res = await API.post( + '/api/channel/fetch_models', + { + base_url: inputs['base_url'], + type: inputs['type'], + key: inputs['key'], + }, + { skipErrorHandler: true }, + ); - if (res.data && res.data.success) { + if (res && res.data && res.data.success) { models.push(...res.data.data); } else { err = true; @@ -747,7 +751,7 @@ const EditChannel = (props) => { { - {isEdit && ( - - )} +