From eb1d4ee693b59a3d0ca5cbc7d2f2110dc265d705 Mon Sep 17 00:00:00 2001 From: foxhui Date: Sat, 10 Jan 2026 18:18:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9B=A0=E6=9C=AA?= =?UTF-8?q?=E6=8D=95=E8=8E=B7=E7=9A=84=E8=B6=85=E6=97=B6=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E7=A8=8B=E5=BA=8F=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ src/backend/utils/error.js | 7 +++++++ src/backend/utils/page.js | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 008e634..5185109 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.4.4] - 2026-01-10 + +### 🐛 Fixed +- **未捕获的超时错误** + - 修复因未捕获的超时错误导致的程序崩溃 + ## [3.4.3] - 2025-12-26 ### ✨ Added diff --git a/src/backend/utils/error.js b/src/backend/utils/error.js index 257914b..9d243cb 100644 --- a/src/backend/utils/error.js +++ b/src/backend/utils/error.js @@ -57,6 +57,13 @@ export function normalizePageError(err, meta = {}) { logger.error('适配器', '页面状态无效', meta); return { error: '页面状态无效,请重新初始化', code: ADAPTER_ERRORS.PAGE_INVALID, retryable: true }; } + // API_TIMEOUT: waitApiResponse 内部转换后的超时错误 + if (err.message?.startsWith('API_TIMEOUT:')) { + const timeoutMsg = err.message.replace('API_TIMEOUT: ', ''); + logger.error('适配器', timeoutMsg, meta); + return { error: timeoutMsg, code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true }; + } + // 兼容原生 TimeoutError (其他地方抛出的) if (err.name === 'TimeoutError' || err.message?.includes('Timeout')) { logger.error('适配器', '请求超时', meta); return { error: '请求超时 (120秒), 请检查网络或稍后重试', code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true }; diff --git a/src/backend/utils/page.js b/src/backend/utils/page.js index 62f7e76..5ff344e 100644 --- a/src/backend/utils/page.js +++ b/src/backend/utils/page.js @@ -337,6 +337,14 @@ export async function waitApiResponse(page, options = {}) { } return response; + } catch (e) { + // 检测超时错误,转换为标准错误类型 + if (e.name === 'TimeoutError' || e.message?.includes('Timeout')) { + const timeoutSec = Math.round(timeout / 1000); + throw new Error(`API_TIMEOUT: 等待响应超时 (${timeoutSec}秒)`); + } + // 其他错误直接重新抛出(如 PAGE_CLOSED, PAGE_CRASHED 等) + throw e; } finally { pageWatcher.cleanup(); }