From 55660e8c4ee8d570c38d1fd3ce163077d2304a5a Mon Sep 17 00:00:00 2001 From: Isaac Date: Thu, 30 Jan 2025 03:32:02 +0000 Subject: [PATCH] feat: handle exit signals --- src/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/index.js b/src/index.js index 90e43b0..4e1a60b 100644 --- a/src/index.js +++ b/src/index.js @@ -62,6 +62,16 @@ const logger = require('./lib/logger'); let config = YAML.parse(fs.readFileSync(path.join(__dirname, 'user/config.yml'), 'utf8')); let log = logger(config); +function exit(signal) { + log.notice(`Received ${signal}`); + client.destroy(); + process.exit(0); +} + +process.on('SIGTERM', () => exit('SIGTERM')); + +process.on('SIGINT', () => exit('SIGINT')); + process.on('uncaughtException', (error, origin) => { log.notice(`Discord Tickets v${pkg.version} on Node.js ${process.version} (${process.platform})`); log.warn(origin === 'uncaughtException' ? 'Uncaught exception' : 'Unhandled promise rejection' + ` (${error.name})`);