xmpp-bot/lib/error/index.js

31 lines
813 B
JavaScript
Raw Normal View History

2019-10-13 03:38:25 +02:00
/**
* Close handler
*
* Disconnect bot from XMPP server before app closes
*
* @file This files defines the closing handler
* @author nioc
* @since 1.0.0
* @license AGPL-3.0+
*/
module.exports = (logger, xmpp) => {
let nodeCleanup = require('node-cleanup')
nodeCleanup(function (exitCode, signal) {
logger.warn(`Received ${exitCode}/${signal} (application is closing), disconnect from XMPP server`)
try {
xmpp.close()
2019-11-21 22:38:10 +01:00
.then(() => {
logger.debug('Connection successfully closed')
})
.catch((error) => {
logger.error('Error during XMPP disconnection', error)
})
2019-10-13 03:38:25 +02:00
} catch (error) {
logger.error('Error during XMPP disconnection: ' + error.message)
}
logger.debug('Synchronize logs file')
logger.shutdown()
})
}