Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exception handling TimeoutError (#20) #21

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@ async function lookup(store: Store) {
width: Config.page.width
});

await page.goto(link.url, {waitUntil: 'networkidle0'});
const graphicsCard = `${link.brand} ${link.model}`;

try {
await page.goto(link.url, {waitUntil: 'networkidle0'});
} catch {
Logger.error(`✖ [${store.name}] ${graphicsCard} skipping; timed out`);
return;
}

const bodyHandle = await page.$('body');
const textContent = await page.evaluate(body => body.textContent, bodyHandle);

Logger.debug(textContent);

const graphicsCard = `${link.brand} ${link.model}`;

if (isOutOfStock(textContent, link.oosLabels)) {
Logger.info(`✖ [${store.name}] ${graphicsCard} is still out of stock`);
} else {
Expand Down