feat: handle exit signals

This commit is contained in:
Isaac 2025-01-30 03:32:02 +00:00
parent 80ee7b3d4e
commit 55660e8c4e
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33

View File

@ -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})`);