mirror of
https://github.com/foxhui/WebAI2API.git
synced 2026-06-16 21:03:59 +08:00
fix: 修复因未捕获的超时错误导致的程序崩溃
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user