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(); }