SIGINT handler to not notify about error on Ctrl-C

This commit is contained in:
Ralf Vogler 2023-02-22 00:15:03 +01:00
parent c1cd2db721
commit 66694d65e5
3 changed files with 24 additions and 6 deletions

View file

@ -12,6 +12,12 @@ console.log(datetime(), 'started checking prime-gaming');
const db = await jsonDb('prime-gaming.json');
db.data ||= {};
let exit = false;
process.on('SIGINT', () => { // e.g. when killed by Ctrl-C
console.log('\nInterrupted by SIGINT. Exit! Exception shows where the script was:\n');
exit = true;
});
// https://playwright.dev/docs/auth#multi-factor-authentication
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
headless: cfg.headless,
@ -165,7 +171,7 @@ try {
} catch (error) {
console.error(error); // .toString()?
process.exitCode = 1;
if (error.message && !error.message.includes('Target closed')) // e.g. when killed by Ctrl-C
if (error.message && !exit)
notify(`prime-gaming failed: ${error.message.split('\n')[0]}`);
} finally {
await db.write(); // write out json db