flat: ts + 接口错误处理

This commit is contained in:
Apcallover
2025-11-11 21:31:32 +08:00
parent 59e04e53b1
commit 120bad4abe
5 changed files with 58 additions and 3 deletions

View File

@@ -98,7 +98,7 @@ export function setupLiveHandlers() {
contextIsolation: false,
},
});
liveWindow.webContents.openDevTools();
// liveWindow.webContents.openDevTools();
liveWindow.on("closed", () => {
liveWindow = null;
});
@@ -134,6 +134,33 @@ async function getSessionId(requestBody: object) {
body: JSON.stringify(requestBody),
});
// 首先检查响应内容类型
const contentType = response.headers.get("content-type");
if (!contentType || !contentType.includes("application/json")) {
// 如果不是JSON读取原始文本进行调试
const rawText = await response.text();
console.warn("服务器返回非JSON响应:", rawText);
// 尝试解析可能的JSON响应即使Content-Type不正确
try {
const data = JSON.parse(rawText);
if (response.ok && data.sessionid) {
return { success: true, sessionId: data.sessionid };
} else {
return {
success: false,
error: data.message || "服务器返回非JSON格式",
};
}
} catch (parseError) {
return {
success: false,
error: `服务器响应格式错误: ${rawText.substring(0, 100)}...`,
};
}
}
// 如果是JSON正常解析
const data = await response.json();
if (response.ok && data.sessionid) {

View File

@@ -141,6 +141,7 @@ export function setupWorkflowHandlers() {
// 将整个工作流封装在 IPC Handler 中
ipcMain.handle("run-job-workflow", async (_, userQuery) => {
console.log("工作流: 正在准备工作...");
let currentJobData = userQuery || {};
let answerText = "";