feat(errors): add CORS error handling for cross-origin requests

This commit is contained in:
HouYunFei
2026-08-18 15:39:05 +08:00
parent ba21c77201
commit 9414048f9d
7 changed files with 7 additions and 2 deletions
+1
View File
@@ -10,6 +10,7 @@
+ [调整] 双击多图节点统一放大预览图片,仅通过右上角张数按钮展开或收起图片组。
+ [修复] 文本节点和生成配置新增独立的文本生成次数,默认一次且不再误用生图数量。
+ [修复] 节点缩放期间暂停渲染提示词面板,避免导入图片后立即缩放导致页面崩溃。
+ [优化] 生图、视频和音频请求遇到跨域拦截时明确提示需要通过自己的服务转发。
+ [优化] 图片工具条默认仅显示图标并移除图片、文本编辑入口,单击图片、文本或视频节点直接打开下方提示词面板。
+ [优化] 画布多图展开状态改为由用户主动控制,操作画布其他区域时不再自动收起。
+ [优化] 展开的多图子图支持双击直接放大预览,无需先设为主图。
@@ -73,3 +73,4 @@ description: 当前版本已实现但仍需人工验证的变更项
- Agent 对话滚动:从历史或日志切回对话、恢复其他会话时应自动定位到最新消息;手动向上浏览后应显示与日志完全相同尺寸、位置和样式的居中圆形向下箭头,新消息不强制打断阅读,对话底部不应出现额外留白,点击按钮后平滑回到底部并继续跟随新消息。
- Agent 消息区分:用户消息应在右侧使用透明无气泡排版,AI 回复应在左侧使用无头像的开放式 Markdown 排版;长文本、多张附件、错误消息及浅色/深色主题下均应清晰且不溢出。
- Agent 命令记录:命令执行中应显示运行状态;完成后,同一轮相邻命令应合并为「已执行 N 条命令」折叠行且默认不显示原始命令,单条展开后直接显示完整详情,多条展开后可分别查看命令、输出和退出状态;对话结束或刷新后分组与记录不应消失。
- 跨域提示:生图、视频或音频请求被浏览器跨域策略拦截时,应明确提示需要通过自己的服务转发请求,不再只显示笼统的网络错误。
+1 -1
View File
@@ -44,7 +44,7 @@ export default {
returns: { image: "Text-to-image and image editing use different APIs; distinguish them by whether images is empty. Return an image URL or data URL, an array of them, or [{ dataUrl }] / [{ url }] / [{ b64_json }].", video: "Poll inside the script and return { url }, { blob }, or a video URL string.", audio: "Return a Blob, base64/data URL string, or { b64_json } / { data } / { url }.", text: "Push streaming output with onDelta(text), then return the complete text string." },
templates: { openai: "OpenAI format", gemini: "Gemini format", imageOpenai: "Image generation and editing use different endpoints; distinguish them by whether images is empty.", availableImage: "Available: prompt, images(dataURL[]), params{size,quality,count}, model, baseUrl, apiKey", textToImage: "Text to image: /images/generations (JSON)", imageToImage: "Image editing: /images/edits (multipart/form-data with reference images uploaded as files)", formDataHeader: "Do not set Content-Type manually; let the browser add the boundary", imageGemini: "Gemini image generation and editing both use generateContent, with references in parts.inline_data.", availableImageGemini: "Available: prompt, images(dataURL[]), model, baseUrl, apiKey", videoOpenai: "Video with polling handled inside the script. Available: prompt, images(dataURL[]), params{seconds,size,resolution,ratio}", videoGemini: "Gemini (Veo) video: submit with predictLongRunning and poll the operation for the video URI.", availableVideoGemini: "Available: prompt, images(dataURL[]), params, model, baseUrl, apiKey", geminiNoVideoUri: "Gemini did not return a video URI", audioOpenai: "Audio TTS. Available: prompt, params{voice,format,speed,instructions}, model", audioGemini: "Gemini TTS: generateContent with AUDIO modality, returning base64 PCM in inlineData.data.", availableAudioGemini: "Available: prompt, params{voice}, model, baseUrl, apiKey", geminiNoAudio: "Gemini did not return audio", textOpenai: "Text chat using the OpenAI Responses API. Available: messages([{role,content}]), systemPrompt, model, reasoningEffort", textGemini: "Gemini text: generateContent with the system message in systemInstruction.", availableTextGemini: "Available: messages([{role,content}]), systemPrompt, model, baseUrl, apiKey" },
},
apiErrors: { requestFailed: "Request failed", requestCanceled: "Request canceled", baseUrlRequired: "Configure the Base URL first", apiKeyRequired: "Configure the API key first", authenticationFailed: "Authentication failed. Check the API key, plan permissions, and model permissions.", rateLimited: "The request was rate-limited or the quota is insufficient. Try again later.", notFound: "The endpoint was not found (404). Check the Base URL and selected model.", badGateway: "Gateway error (502). The API service is temporarily unavailable.", serviceBusy: "Service unavailable (503). Try again later.", httpFailed: "Request failed (HTTP {{status}}). Check the Base URL and API key.", htmlError: "The service returned an HTML error page ({{preview}})", audioModelRequired: "Configure an audio model first", audioGenerationFailed: "Audio generation failed", scriptNoAudio: "The model request script did not return audio", geminiAudioUnsupported: "The Gemini API format does not support audio generation. Use an OpenAI-format provider.", invalidImageSizeFormat: "Unsupported image size. Use auto, 9:16, or 1024x1024.", positiveImageRatio: "The image ratio must use positive numbers, such as 9:16.", imageRatioLimit: "The image aspect ratio cannot exceed 3:1. Adjust the dimensions.", positiveImageDimensions: "Image dimensions must be positive integers, such as 1024x1024.", imageDimensionStep: "Image width and height must be multiples of 16.", imageEdgeLimit: "The longest image edge cannot exceed 3840px.", imagePixelLimit: "The total image pixel count must be between 655360 and 8294400.", unknownImageResponse: "The API returned data in an unknown format (fields: {{fields}}). Check model or API compatibility.", noImageReturned: "The API did not return an image. The prompt may have triggered safety review or the model may not support this operation.", geminiRejected: "Gemini rejected the request: {{reason}}", geminiNoImage: "The Gemini API did not return an image", geminiMaskUnsupported: "The Gemini API format does not support mask editing", maskModelUnsupported: "This model does not support mask editing. Use another provider.", noContent: "No content returned", modelReadFailed: "Failed to load models", videoTimeout: "{{provider}}video generation timed out. Try again later.", pluginVideoExpired: "The plugin video task has expired. Generate it again.", scriptNoVideo: "The model request script did not return a video", noPlayableVideo: "The video API did not return a playable video", noVideoTaskId: "The video API did not return a task ID", videoTaskCreateFailed: "Failed to create video task", videoGenerationFailed: "Video generation failed", videoTaskQueryFailed: "Failed to query video task", videoPromptRequired: "Enter a video prompt or connect a reference image, video, or audio asset", referenceImageReadFailed: "Failed to read the reference image. Choose another image or upload it again.", invalidReferenceVideo: "A reference video must be a public URL, asset ID, or locally saved video", invalidReferenceAudio: "Reference audio must be a public URL, asset ID, or locally saved audio file", videoModelRequired: "Configure a video model first", geminiVideoUnsupported: "The Gemini API format does not support video generation. Use an OpenAI-format provider.", noVideoTask: "The API did not return a video task", videoDownloadFailed: "Failed to download video", localAssetReadFailed: "Failed to read local asset" },
apiErrors: { requestFailed: "Request failed", requestCanceled: "Request canceled", corsRequired: "The browser blocked this cross-origin request. Route it through your own server", baseUrlRequired: "Configure the Base URL first", apiKeyRequired: "Configure the API key first", authenticationFailed: "Authentication failed. Check the API key, plan permissions, and model permissions.", rateLimited: "The request was rate-limited or the quota is insufficient. Try again later.", notFound: "The endpoint was not found (404). Check the Base URL and selected model.", badGateway: "Gateway error (502). The API service is temporarily unavailable.", serviceBusy: "Service unavailable (503). Try again later.", httpFailed: "Request failed (HTTP {{status}}). Check the Base URL and API key.", htmlError: "The service returned an HTML error page ({{preview}})", audioModelRequired: "Configure an audio model first", audioGenerationFailed: "Audio generation failed", scriptNoAudio: "The model request script did not return audio", geminiAudioUnsupported: "The Gemini API format does not support audio generation. Use an OpenAI-format provider.", invalidImageSizeFormat: "Unsupported image size. Use auto, 9:16, or 1024x1024.", positiveImageRatio: "The image ratio must use positive numbers, such as 9:16.", imageRatioLimit: "The image aspect ratio cannot exceed 3:1. Adjust the dimensions.", positiveImageDimensions: "Image dimensions must be positive integers, such as 1024x1024.", imageDimensionStep: "Image width and height must be multiples of 16.", imageEdgeLimit: "The longest image edge cannot exceed 3840px.", imagePixelLimit: "The total image pixel count must be between 655360 and 8294400.", unknownImageResponse: "The API returned data in an unknown format (fields: {{fields}}). Check model or API compatibility.", noImageReturned: "The API did not return an image. The prompt may have triggered safety review or the model may not support this operation.", geminiRejected: "Gemini rejected the request: {{reason}}", geminiNoImage: "The Gemini API did not return an image", geminiMaskUnsupported: "The Gemini API format does not support mask editing", maskModelUnsupported: "This model does not support mask editing. Use another provider.", noContent: "No content returned", modelReadFailed: "Failed to load models", videoTimeout: "{{provider}}video generation timed out. Try again later.", pluginVideoExpired: "The plugin video task has expired. Generate it again.", scriptNoVideo: "The model request script did not return a video", noPlayableVideo: "The video API did not return a playable video", noVideoTaskId: "The video API did not return a task ID", videoTaskCreateFailed: "Failed to create video task", videoGenerationFailed: "Video generation failed", videoTaskQueryFailed: "Failed to query video task", videoPromptRequired: "Enter a video prompt or connect a reference image, video, or audio asset", referenceImageReadFailed: "Failed to read the reference image. Choose another image or upload it again.", invalidReferenceVideo: "A reference video must be a public URL, asset ID, or locally saved video", invalidReferenceAudio: "Reference audio must be a public URL, asset ID, or locally saved audio file", videoModelRequired: "Configure a video model first", geminiVideoUnsupported: "The Gemini API format does not support video generation. Use an OpenAI-format provider.", noVideoTask: "The API did not return a video task", videoDownloadFailed: "Failed to download video", localAssetReadFailed: "Failed to read local asset" },
prompts: {
title: "Prompt Center",
library: "Prompt Library",
+1 -1
View File
@@ -44,7 +44,7 @@ export default {
returns: { image: "文生图(images 为空)和图生图(images 有参考图)接口不同,脚本需自行区分;返回图片 URL 或 dataURL 字符串,也可返回它们的数组,或 [{ dataUrl }] / [{ url }] / [{ b64_json }]", video: "脚本内部完成轮询,返回 { url } 或 { blob } 或视频 URL 字符串", audio: "返回 Blob,或 base64 / dataURL 字符串,或 { b64_json } / { data } / { url }", text: "用 onDelta(text) 推送流式,最终 return 完整文本字符串" },
templates: { openai: "OpenAI 规范", gemini: "Gemini 规范", imageOpenai: "生图 / 改图:两者接口不同,用 images 是否为空来区分。", availableImage: "可用:prompt、images(dataURL[])、params{size,quality,count}、model、baseUrl、apiKey", textToImage: "文生图:/images/generations(JSON)", imageToImage: "图生图:/images/edits(multipart/form-data,参考图作为文件上传)", formDataHeader: "不要手动设 Content-Type,交给浏览器带 boundary", imageGemini: "Gemini 文生图 / 图生图:都走 generateContent,参考图放进 parts 的 inline_data。", availableImageGemini: "可用:prompt、images(dataURL[])、model、baseUrl、apiKey", videoOpenai: "视频(脚本内部自行轮询)。可用:prompt、images(dataURL[])、params{seconds,size,resolution,ratio}", videoGemini: "Gemini(Veo) 视频:predictLongRunning 提交,轮询 operation 拿视频 URI。", availableVideoGemini: "可用:prompt、images(dataURL[])、params、model、baseUrl、apiKey", geminiNoVideoUri: "Gemini 未返回视频 URI", audioOpenai: "音频 TTS。可用:prompt、params{voice,format,speed,instructions}、model", audioGemini: "Gemini TTS:generateContent + AUDIO 模态,返回 base64 PCM(音频数据在 inlineData.data)。", availableAudioGemini: "可用:prompt、params{voice}、model、baseUrl、apiKey", geminiNoAudio: "Gemini 未返回音频", textOpenai: "文本对话(OpenAI Responses 接口)。可用:messages([{role,content}])、systemPrompt、model、reasoningEffort", textGemini: "Gemini 文本:generateContent,system 消息放 systemInstruction。", availableTextGemini: "可用:messages([{role,content}])、systemPrompt、model、baseUrl、apiKey" },
},
apiErrors: { requestFailed: "请求失败", requestCanceled: "请求已取消", baseUrlRequired: "请先配置 Base URL", apiKeyRequired: "请先配置 API Key", authenticationFailed: "鉴权失败,请检查 API Key、套餐权限或模型权限", rateLimited: "请求被限流或额度不足,请稍后重试", notFound: "接口地址不存在(404),请检查 Base URL 和模型选择", badGateway: "网关错误(502),接口服务暂时不可用,请稍后重试", serviceBusy: "服务繁忙(503),请稍后重试", httpFailed: "请求失败(HTTP {{status}}),请检查 Base URL 和 API Key 是否正确", htmlError: "服务返回了 HTML 错误页面({{preview}})", audioModelRequired: "请先配置音频模型", audioGenerationFailed: "音频生成失败", scriptNoAudio: "模型调用脚本没有返回音频", geminiAudioUnsupported: "Gemini 调用格式暂不支持音频生成,请使用 OpenAI 格式渠道", invalidImageSizeFormat: "图像尺寸格式不支持,请使用 auto、9:16 或 1024x1024", positiveImageRatio: "图像比例必须是正数,例如 9:16", imageRatioLimit: "图像宽高比不能超过 3:1,请调整尺寸", positiveImageDimensions: "图像尺寸必须是正整数,例如 1024x1024", imageDimensionStep: "图像尺寸的宽高必须是 16 的倍数,请调整尺寸", imageEdgeLimit: "图像尺寸最长边不能超过 3840px,请调整尺寸", imagePixelLimit: "图像总像素需在 655360 到 8294400 之间,请调整尺寸", unknownImageResponse: "接口返回了未知格式的数据(字段:{{fields}}),请检查模型或接口兼容性", noImageReturned: "接口没有返回图片,请检查提示词是否触发安全审核或模型是否支持该操作", geminiRejected: "Gemini 拒绝了本次请求:{{reason}}", geminiNoImage: "Gemini 接口没有返回图片", geminiMaskUnsupported: "Gemini 调用格式暂不支持蒙版编辑", maskModelUnsupported: "蒙版编辑暂不支持该模型,请使用其他渠道", noContent: "没有返回内容", modelReadFailed: "读取模型失败", videoTimeout: "{{provider}}视频生成超时,请稍后重试", pluginVideoExpired: "插件视频任务已失效,请重新生成", scriptNoVideo: "模型调用脚本没有返回视频", noPlayableVideo: "视频接口没有返回可播放的视频", noVideoTaskId: "视频接口没有返回任务 ID", videoTaskCreateFailed: "视频任务创建失败", videoGenerationFailed: "视频生成失败", videoTaskQueryFailed: "视频任务查询失败", videoPromptRequired: "请输入视频提示词,或连接参考图片/视频/音频", referenceImageReadFailed: "参考图读取失败,请换一张图片或重新上传", invalidReferenceVideo: "参考视频必须是公网 URL、资产 ID,或本地已保存的视频", invalidReferenceAudio: "参考音频必须是公网 URL、资产 ID,或本地已保存的音频", videoModelRequired: "请先配置视频模型", geminiVideoUnsupported: "Gemini 调用格式暂不支持视频生成,请使用 OpenAI 格式渠道", noVideoTask: "接口没有返回视频任务", videoDownloadFailed: "视频下载失败", localAssetReadFailed: "读取本地资产失败" },
apiErrors: { requestFailed: "请求失败", requestCanceled: "请求已取消", corsRequired: "请求被浏览器跨域策略拦截,请通过自己的服务转发请求", baseUrlRequired: "请先配置 Base URL", apiKeyRequired: "请先配置 API Key", authenticationFailed: "鉴权失败,请检查 API Key、套餐权限或模型权限", rateLimited: "请求被限流或额度不足,请稍后重试", notFound: "接口地址不存在(404),请检查 Base URL 和模型选择", badGateway: "网关错误(502),接口服务暂时不可用,请稍后重试", serviceBusy: "服务繁忙(503),请稍后重试", httpFailed: "请求失败(HTTP {{status}}),请检查 Base URL 和 API Key 是否正确", htmlError: "服务返回了 HTML 错误页面({{preview}})", audioModelRequired: "请先配置音频模型", audioGenerationFailed: "音频生成失败", scriptNoAudio: "模型调用脚本没有返回音频", geminiAudioUnsupported: "Gemini 调用格式暂不支持音频生成,请使用 OpenAI 格式渠道", invalidImageSizeFormat: "图像尺寸格式不支持,请使用 auto、9:16 或 1024x1024", positiveImageRatio: "图像比例必须是正数,例如 9:16", imageRatioLimit: "图像宽高比不能超过 3:1,请调整尺寸", positiveImageDimensions: "图像尺寸必须是正整数,例如 1024x1024", imageDimensionStep: "图像尺寸的宽高必须是 16 的倍数,请调整尺寸", imageEdgeLimit: "图像尺寸最长边不能超过 3840px,请调整尺寸", imagePixelLimit: "图像总像素需在 655360 到 8294400 之间,请调整尺寸", unknownImageResponse: "接口返回了未知格式的数据(字段:{{fields}}),请检查模型或接口兼容性", noImageReturned: "接口没有返回图片,请检查提示词是否触发安全审核或模型是否支持该操作", geminiRejected: "Gemini 拒绝了本次请求:{{reason}}", geminiNoImage: "Gemini 接口没有返回图片", geminiMaskUnsupported: "Gemini 调用格式暂不支持蒙版编辑", maskModelUnsupported: "蒙版编辑暂不支持该模型,请使用其他渠道", noContent: "没有返回内容", modelReadFailed: "读取模型失败", videoTimeout: "{{provider}}视频生成超时,请稍后重试", pluginVideoExpired: "插件视频任务已失效,请重新生成", scriptNoVideo: "模型调用脚本没有返回视频", noPlayableVideo: "视频接口没有返回可播放的视频", noVideoTaskId: "视频接口没有返回任务 ID", videoTaskCreateFailed: "视频任务创建失败", videoGenerationFailed: "视频生成失败", videoTaskQueryFailed: "视频任务查询失败", videoPromptRequired: "请输入视频提示词,或连接参考图片/视频/音频", referenceImageReadFailed: "参考图读取失败,请换一张图片或重新上传", invalidReferenceVideo: "参考视频必须是公网 URL、资产 ID,或本地已保存的视频", invalidReferenceAudio: "参考音频必须是公网 URL、资产 ID,或本地已保存的音频", videoModelRequired: "请先配置视频模型", geminiVideoUnsupported: "Gemini 调用格式暂不支持视频生成,请使用 OpenAI 格式渠道", noVideoTask: "接口没有返回视频任务", videoDownloadFailed: "视频下载失败", localAssetReadFailed: "读取本地资产失败" },
prompts: {
title: "提示词中心",
library: "提示词库",
+1
View File
@@ -135,6 +135,7 @@ function readApiErrorMessage(value: unknown): string {
function readAxiosError(error: unknown, fallback: string) {
if (axios.isCancel(error)) return apiText("requestCanceled");
if (axios.isAxiosError(error)) {
if (!error.response && error.code === "ERR_NETWORK") return apiText("corsRequired");
const responseData = error.response?.data;
const apiMsg = readApiErrorMessage(responseData);
if (apiMsg) return apiMsg;
+1
View File
@@ -304,6 +304,7 @@ function readApiErrorMessage(value: unknown): string {
function readAxiosError(error: unknown, fallback: string) {
if (axios.isCancel(error)) return apiText("requestCanceled");
if (axios.isAxiosError(error)) {
if (!error.response && error.code === "ERR_NETWORK") return apiText("corsRequired");
const responseData = error.response?.data;
// Prefer the API error from the response body.
const apiMsg = readApiErrorMessage(responseData);
+1
View File
@@ -239,6 +239,7 @@ function readApiErrorMessage(value: unknown): string {
function readAxiosError(error: unknown, fallback: string) {
if (axios.isCancel(error)) return apiText("requestCanceled");
if (axios.isAxiosError<{ error?: { message?: string }; msg?: string; message?: string; code?: number | string }>(error)) {
if (!error.response && error.code === "ERR_NETWORK") return apiText("corsRequired");
const responseData = error.response?.data;
return readApiErrorMessage(responseData) || statusMessage(error.response?.status, fallback);
}