pipobscure / NodeJS-AsteriskManager

NodeJS Asterisk Manager API
Other
247 stars 103 forks source link

Error on initial login is silently ignored #58

Open z3ntu opened 6 years ago

z3ntu commented 6 years ago
var config = require('config');
var asterisk_manager = require('asterisk-manager');
var aConfig = config.get('asterisk');
var ami = new asterisk_manager(
    aConfig.port,
    aConfig.host,
    aConfig.username,
    aConfig.password,
    true);

When this is run and something (e.g. the password) is wrong, then the error is silently ignored (see https://github.com/pipobscure/NodeJS-AsteriskManager/blob/master/lib/ami.js#L50). Only after the object creation I can do

ami.on('error', function (err) {
    console.log(err);
});

to see the error. Is there another way I am not seeing?

micodix commented 2 years ago

Hi,

the handler for errors caused by the socket connection is set here: https://github.com/pipobscure/NodeJS-AsteriskManager/blob/master/lib/ami.js#L82 The errors themselves are emitted here: https://github.com/pipobscure/NodeJS-AsteriskManager/blob/master/lib/ami.js#L87

To receive them, you must of course set an error listener in your code.

The code section you mentioned (https://github.com/pipobscure/NodeJS-AsteriskManager/blob/master/lib/ami.js#L49-L51) contains only listeners internally used by the manager instance for further processing of events. An error handler is obviously not needed (yet) at this point.