|
@@ -398,38 +398,34 @@ export class XiaohongshuAccountOverviewImportService {
|
|
|
await page.waitForTimeout(3000); // 等几秒,让页面发起 account/base 请求
|
|
await page.waitForTimeout(3000); // 等几秒,让页面发起 account/base 请求
|
|
|
|
|
|
|
|
if (page.url().includes('login')) {
|
|
if (page.url().includes('login')) {
|
|
|
- // 第一次检测到登录失效时,尝试刷新账号
|
|
|
|
|
|
|
+ // 第一次检测到登录失效时,尝试刷新账号;刷新失败则仅跳过本账号,不影响其他账号
|
|
|
if (!isRetry) {
|
|
if (!isRetry) {
|
|
|
logger.info(`[XHS Import] Login expired detected for account ${account.id}, attempting to refresh...`);
|
|
logger.info(`[XHS Import] Login expired detected for account ${account.id}, attempting to refresh...`);
|
|
|
|
|
+ responsePromise.catch(() => {}); // 关闭前吸收 rejection,避免 context 关闭导致进程崩溃
|
|
|
await context.close();
|
|
await context.close();
|
|
|
if (shouldClose) await browser.close();
|
|
if (shouldClose) await browser.close();
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
const accountService = new AccountService();
|
|
const accountService = new AccountService();
|
|
|
const refreshResult = await accountService.refreshAccount(account.userId, account.id);
|
|
const refreshResult = await accountService.refreshAccount(account.userId, account.id);
|
|
|
-
|
|
|
|
|
if (refreshResult.needReLogin) {
|
|
if (refreshResult.needReLogin) {
|
|
|
- // 刷新后仍需要重新登录,走原先的失效流程
|
|
|
|
|
- logger.warn(`[XHS Import] Account ${account.id} refresh failed, still needs re-login`);
|
|
|
|
|
- throw new Error('未登录/需要重新登录(跳转到 login)');
|
|
|
|
|
|
|
+ logger.warn(`[XHS Import] Account ${account.id} refresh failed, still needs re-login, skip this account`);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 刷新成功,重新获取账号信息并重试导入
|
|
|
|
|
- logger.info(`[XHS Import] Account ${account.id} refreshed successfully, retrying import...`);
|
|
|
|
|
const refreshedAccount = await this.accountRepository.findOne({ where: { id: account.id } });
|
|
const refreshedAccount = await this.accountRepository.findOne({ where: { id: account.id } });
|
|
|
if (!refreshedAccount) {
|
|
if (!refreshedAccount) {
|
|
|
- throw new Error('账号刷新后未找到');
|
|
|
|
|
|
|
+ logger.warn(`[XHS Import] Account ${account.id} refreshed but not found, skip`);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 递归调用,标记为重试
|
|
|
|
|
|
|
+ logger.info(`[XHS Import] Account ${account.id} refreshed successfully, retrying import...`);
|
|
|
return await this.importAccountLast30Days(refreshedAccount, true);
|
|
return await this.importAccountLast30Days(refreshedAccount, true);
|
|
|
} catch (refreshError) {
|
|
} catch (refreshError) {
|
|
|
- logger.error(`[XHS Import] Account ${account.id} refresh failed:`, refreshError);
|
|
|
|
|
- throw new Error('未登录/需要重新登录(跳转到 login)');
|
|
|
|
|
|
|
+ logger.error(`[XHS Import] Account ${account.id} refresh failed, skip this account:`, refreshError);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- // 已经是重试了,不再尝试刷新
|
|
|
|
|
- throw new Error('未登录/需要重新登录(跳转到 login)');
|
|
|
|
|
|
|
+ responsePromise.catch(() => {});
|
|
|
|
|
+ logger.warn(`[XHS Import] Account ${account.id} still login expired after retry, skip this account`);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|