NodeJs / Bluebird - keep getting raw rejection Error

I am creating a daemon that listens for a TCP connection> sends commands> listen for events.

so I decided to use the bluebird to get rid of all the callbacks .. but I have a problem ... I cannot find the rejected error .... I have no idea what is wrong here, this is my code

Promise:

function exec(cmd, params, options) {
    return new Promise(function(resolve, reject) {
        server.send(cmd, params || {}, options || [], function (err, res, rawRes) {
            if (err) reject(err.msg);
            resolve(res);
        });
    });
}

performance:

exec("login", {
    // lOGIN
    client_login_name: conf.user,
    client_login_password: conf.pass
}).then(exec("use", {
    // SELECT SERVER
    sid: 4
})).then(exec("clientupdate", {
    // CHANGE NICKNAME
    client_nickname: conf.nick
})).catch(function (err) {
    log.error(err);
});

error (server is not running) - this is an error in reject(err.msg):

Unhandled rejection Error: server is not running
at Object.ensureErrorObject (D:\DEV\node\a90s\node_modules\bluebird\js\main\util.js:261:20)
at Promise._rejectCallback (D:\DEV\node\a90s\node_modules\bluebird\js\main\promise.js:465:22)
at D:\DEV\node\a90s\node_modules\bluebird\js\main\promise.js:482:17
at Object.cb (D:\DEV\node\a90s\modules\ts3interface.js:20:26)
at LineInputStream.<anonymous> (D:\DEV\node\a90s\node_modules\node-teamspeak\index.js:170:47)
at LineInputStream.emit (events.js:107:17)
at LineInputStream._events.line (D:\DEV\node\a90s\node_modules\node-teamspeak\node_modules\line-input-stream\lib\line-input-stream.js:8:8)
at Array.forEach (native)
at Socket.<anonymous> (D:\DEV\node\a90s\node_modules\node-teamspeak\node_modules\line-input-stream\lib\line-input-stream.js:36:9)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)

Thanks in advance:)

+4
source share
2 answers

You should pass callbacks to .then, not promises (so that your calls come back exec).

exec("login", {
    // lOGIN
    client_login_name: conf.user,
    client_login_password: conf.pass
}).then(function(loginresult) {
    // SELECT SERVER
    return exec("use", {
        sid: 4
    });
}).then(function(selectresult) {
    // CHANGE NICKNAME
    return exec("clientupdate", {
        client_nickname: conf.nick
    });
}).catch(function (err) {
    log.error(err);
});
+8
source

reject, resolve. , , , , .

- , .

if (err) {
  reject(err);
} else {
  resolve(thing);
}

, .

+3

All Articles