From a22076bca8276e34725959d962389ab969eb4156 Mon Sep 17 00:00:00 2001 From: Marco Klein Date: Sat, 8 May 2021 09:41:09 +0200 Subject: [PATCH 1/2] fix: check if we are offline before a check fixes #7 --- src/appointments.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/appointments.ts b/src/appointments.ts index 77fbc77..d5ce71a 100644 --- a/src/appointments.ts +++ b/src/appointments.ts @@ -107,6 +107,7 @@ async function proceedWithACode(page: Page, impfCode: string) { debug("No appointments"); return false; } + export async function proceedWithoutACode(page: Page) { debug("Checking without a code"); // no, we have no code @@ -124,6 +125,11 @@ export async function proceedWithoutACode(page: Page) { const appointmentWarning = await page.$("div.alert.alert-danger"); + if (await areWeOffline(page)) { + debug("We are offline or on some different page"); + return false; + } + if (!appointmentWarning) { // code available debug("Appointments available!!"); @@ -133,6 +139,10 @@ export async function proceedWithoutACode(page: Page) { return false; } +async function areWeOffline(page: Page) { + return !(await page.$("footer-copyright")); +} + export async function checkForAppointments( page: Page, impfLocationUrl: string, From 80b1c8fa237cff9fa6e0c904fa34301fcd038dd4 Mon Sep 17 00:00:00 2001 From: Marco Klein Date: Sat, 8 May 2021 09:42:08 +0200 Subject: [PATCH 2/2] fix: check if we are offline with code --- src/appointments.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/appointments.ts b/src/appointments.ts index d5ce71a..eaf7dbc 100644 --- a/src/appointments.ts +++ b/src/appointments.ts @@ -95,6 +95,11 @@ async function proceedWithACode(page: Page, impfCode: string) { await appointmentWarning?.getProperty("innerText") )?.jsonValue(); + if (await areWeOffline(page)) { + debug("We are offline or on some different page"); + return false; + } + if ( !appointmentWarning || !appointmentText ||