mirror of
https://github.com/nioc/xmpp-bot.git
synced 2024-12-04 14:23:35 +01:00
Close service when receiving XMPP error
This commit is contained in:
parent
fab1a00f66
commit
674b8e4380
2 changed files with 9 additions and 1 deletions
|
@ -73,6 +73,7 @@ module.exports = (logger, config) => {
|
|||
// handle error
|
||||
xmpp.on('error', function (err) {
|
||||
logger.error(err)
|
||||
process.exit(99)
|
||||
})
|
||||
|
||||
// connect
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue