Skip to content

Commit eb1d4ee

Browse files
committed
fix: 修复因未捕获的超时错误导致的程序崩溃
1 parent 8c80fa5 commit eb1d4ee

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.4.4] - 2026-01-10
9+
10+
### 🐛 Fixed
11+
- **未捕获的超时错误**
12+
- 修复因未捕获的超时错误导致的程序崩溃
13+
814
## [3.4.3] - 2025-12-26
915

1016
### ✨ Added

src/backend/utils/error.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export function normalizePageError(err, meta = {}) {
5757
logger.error('适配器', '页面状态无效', meta);
5858
return { error: '页面状态无效,请重新初始化', code: ADAPTER_ERRORS.PAGE_INVALID, retryable: true };
5959
}
60+
// API_TIMEOUT: waitApiResponse 内部转换后的超时错误
61+
if (err.message?.startsWith('API_TIMEOUT:')) {
62+
const timeoutMsg = err.message.replace('API_TIMEOUT: ', '');
63+
logger.error('适配器', timeoutMsg, meta);
64+
return { error: timeoutMsg, code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true };
65+
}
66+
// 兼容原生 TimeoutError (其他地方抛出的)
6067
if (err.name === 'TimeoutError' || err.message?.includes('Timeout')) {
6168
logger.error('适配器', '请求超时', meta);
6269
return { error: '请求超时 (120秒), 请检查网络或稍后重试', code: ADAPTER_ERRORS.TIMEOUT_ERROR, retryable: true };

src/backend/utils/page.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,14 @@ export async function waitApiResponse(page, options = {}) {
337337
}
338338

339339
return response;
340+
} catch (e) {
341+
// 检测超时错误,转换为标准错误类型
342+
if (e.name === 'TimeoutError' || e.message?.includes('Timeout')) {
343+
const timeoutSec = Math.round(timeout / 1000);
344+
throw new Error(`API_TIMEOUT: 等待响应超时 (${timeoutSec}秒)`);
345+
}
346+
// 其他错误直接重新抛出(如 PAGE_CLOSED, PAGE_CRASHED 等)
347+
throw e;
340348
} finally {
341349
pageWatcher.cleanup();
342350
}

0 commit comments

Comments
 (0)