Wrap keyword search in try/catch for resilience
Failed keywords log the error and continue to the next one. Not marked complete, so they'll be retried on next run. Also await async onPage callback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,7 @@ export async function searchLinkedIn(page, search, { onPage, onKeyword } = {}) {
|
||||
}
|
||||
await page.waitForTimeout(PAGE_LOAD_WAIT);
|
||||
|
||||
try {
|
||||
let pageNum = 0;
|
||||
while (pageNum < LINKEDIN_MAX_SEARCH_PAGES) {
|
||||
// Scroll to load all cards
|
||||
@@ -129,7 +130,7 @@ export async function searchLinkedIn(page, search, { onPage, onKeyword } = {}) {
|
||||
jobs.push(job);
|
||||
}
|
||||
|
||||
if (pageJobs.length > 0 && callbacks.onPage) callbacks.onPage(pageJobs);
|
||||
if (pageJobs.length > 0 && callbacks.onPage) await callbacks.onPage(pageJobs);
|
||||
|
||||
const nextBtn = await page.$('button[aria-label="View next page"]');
|
||||
if (!nextBtn) break;
|
||||
@@ -137,6 +138,11 @@ export async function searchLinkedIn(page, search, { onPage, onKeyword } = {}) {
|
||||
await page.waitForTimeout(PAGE_LOAD_WAIT);
|
||||
pageNum++;
|
||||
}
|
||||
} catch (kwErr) {
|
||||
console.error(` ❌ Keyword "${keyword}" failed: ${kwErr.message}`);
|
||||
// Don't mark as complete — will be retried on next run
|
||||
continue;
|
||||
}
|
||||
// Mark keyword complete after all its pages are done
|
||||
callbacks.onKeyword?.(ki);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user