fix: update JSONEditor to default to manual mode for invalid JSON and add error message for invalid data

This commit is contained in:
CaIon
2025-08-01 17:21:25 +08:00
parent 277cc1cac8
commit 8df3de9ae5
2 changed files with 15 additions and 3 deletions

View File

@@ -108,11 +108,10 @@ func GeminiTextGenerationStreamHandler(c *gin.Context, info *relaycommon.RelayIn
// 直接发送 GeminiChatResponse 响应
err = helper.StringData(c, data)
info.SendResponseCount++
if err != nil {
common.LogError(c, err.Error())
}
info.SendResponseCount++
return true
})

View File

@@ -65,7 +65,8 @@ const JSONEditor = ({
const keyCount = Object.keys(parsed).length;
return keyCount > 10 ? 'manual' : 'visual';
} catch (error) {
return 'visual';
// JSON无效时默认显示手动编辑模式
return 'manual';
}
}
return 'visual';
@@ -201,6 +202,18 @@ const JSONEditor = ({
// 渲染键值对编辑器
const renderKeyValueEditor = () => {
if (typeof jsonData !== 'object' || jsonData === null) {
return (
<div className="text-center py-6 px-4">
<div className="text-gray-400 mb-2">
<IconCode size={32} />
</div>
<Text type="tertiary" className="text-gray-500 text-sm">
{t('无效的JSON数据请检查格式')}
</Text>
</div>
);
}
const entries = Object.entries(jsonData);
return (