feat: enable fetching model list in creation mode & refine toast-based error handling

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.
This commit is contained in:
t0ng7u
2025-07-11 23:37:47 +08:00
parent c820fda26d
commit a3768dae97
3 changed files with 23 additions and 17 deletions

View File

@@ -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,
};

View File

@@ -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"

View File

@@ -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) => {
<Form.Select
field='models'
label={t('模型')}
placeholder={isEdit ? t('请选择该渠道所支持的模型') : t('创建后可在编辑渠道时获取上游模型列表')}
placeholder={t('请选择该渠道所支持的模型')}
rules={[{ required: true, message: t('请选择模型') }]}
multiple
filter
@@ -763,11 +767,9 @@ const EditChannel = (props) => {
<Button size='small' type='secondary' onClick={() => handleInputChange('models', fullModels)}>
{t('填入所有模型')}
</Button>
{isEdit && (
<Button size='small' type='tertiary' onClick={() => fetchUpstreamModelList('models')}>
{t('获取模型列表')}
</Button>
)}
<Button size='small' type='tertiary' onClick={() => fetchUpstreamModelList('models')}>
{t('获取模型列表')}
</Button>
<Button size='small' type='warning' onClick={() => handleInputChange('models', [])}>
{t('清除所有模型')}
</Button>