clseBrowser func extended to exit w/ code.

This commit is contained in:
2020-06-03 00:20:23 +02:00
committed by KevinMidboe
parent cce9c0d6ea
commit b2e4a46d10

View File

@@ -55,8 +55,7 @@ const exitWithError = (err, message=undefined) => {
if (config.debug === true) if (config.debug === true)
console.error(err) console.error(err)
closeBrowser(); closeBrowserAndExit(1);
process.exit(1);
} }
const dismissCookiePrompt = page => { const dismissCookiePrompt = page => {
@@ -114,8 +113,9 @@ const webscraper = async pageURL => {
.catch(err => exitWithError(err, `Unable to reach url: ${pageURL}`)) .catch(err => exitWithError(err, `Unable to reach url: ${pageURL}`))
} }
function closeBrowser() { function closeBrowserAndExit(status=0) {
browser.close(); browser.close();
process.exit(status);
} }
@@ -126,7 +126,7 @@ function run() {
.then(page => getServiceMessages(page)) .then(page => getServiceMessages(page))
.then(serviceMessages => commitServiceEventToDatabase(serviceMessages, pdfFilename)) .then(serviceMessages => commitServiceEventToDatabase(serviceMessages, pdfFilename))
.then(serviceMessages => notifyIfDown(serviceMessages)) .then(serviceMessages => notifyIfDown(serviceMessages))
.then(closeBrowser) .then(closeBrowserAndExit)
} }
run(); run();