From 15865d04bb9dc877bbb6db6cd1ebe7ed266b7e26 Mon Sep 17 00:00:00 2001 From: ingalls Date: Fri, 14 Jun 2024 08:20:42 -0600 Subject: [PATCH] Update Task --- task.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/task.ts b/task.ts index d9e1dd4..363f00b 100644 --- a/task.ts +++ b/task.ts @@ -24,6 +24,7 @@ export default class Task extends ETL { } async controlLogin(layer: any): Promise { + console.error('ok - Attempting Login'); const loginForm = new FormData(); loginForm.append('operation', 'login'); loginForm.append('post_data', JSON.stringify({ @@ -59,10 +60,13 @@ export default class Task extends ETL { async control(): Promise { const layer = await this.fetchLayer(); + + let loginAttempted = false; let filteredAgencies: Number[] = []; if (!layer.environment.Token || !Array.isArray(layer.environment.Agencies) || !layer.environment.Agencies.length) { filteredAgencies = await this.controlLogin(layer); + loginAttempted = true; } if (Array.isArray(layer.environment.Agencies) && layer.environment.Agencies.length) { @@ -77,7 +81,8 @@ export default class Task extends ETL { }; let errs: Error[] = []; - for (const agency of filteredAgencies) { + for (let i = 0; i < filteredAgencies.length; i++) { + const agency = filteredAgencies[i]; console.error(`ok - getting alerts from ${agency}`); try { @@ -105,7 +110,11 @@ export default class Task extends ETL { } }); + if (loginAttempted) throw new Error('Login Attempted and bad response'); + await this.controlLogin(layer) + loginAttempted = true; + i--; continue; } @@ -117,6 +126,13 @@ export default class Task extends ETL { ) if (alerts.result === 'error') { + if (!loginAttempted && alerts.message === 'Please log in') { + await this.controlLogin(layer); + loginAttempted = true; + i--; + continue; + } + throw new Error(alerts.message); }