Close service when receiving XMPP error

This commit is contained in:
nioc 2019-11-19 22:27:01 +01:00
parent fab1a00f66
commit 674b8e4380
2 changed files with 9 additions and 1 deletions

View file

@ -73,6 +73,7 @@ module.exports = (logger, config) => {
// handle error
xmpp.on('error', function (err) {
logger.error(err)
process.exit(99)
})
// connect

View file

@ -123,7 +123,13 @@ describe('XMPP component', () => {
})
describe('XMPP server send an error', () => {
it('Should log error only', (done) => {
before(() => {
sinon.stub(process, 'exit')
})
after(() => {
process.exit.restore()
})
it('Should log error and exit with 99 code', (done) => {
let error = 'This the error text'
simpleXmppEvents.emit('error', error)
require('fs').readFile(config.logger.file.path + config.logger.file.filename, 'utf8', (err, data) => {
@ -131,6 +137,7 @@ describe('XMPP component', () => {
throw err
}
data.should.match(new RegExp(error + '\n$'))
sinon.assert.calledWith(process.exit, 99)
done()
})
})