From 00a0687d3eba6a8fca871161b447529be00c8896 Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Fri, 18 Sep 2020 10:26:02 -0400 Subject: [PATCH] fix: exception handling `TimeoutError` (#20) (#21) Signed-off-by: Jef LeCompte --- src/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2adcb08..b13a0a7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 {