当我运行代码通过Nexmo发送消息时收到此错误。消息已发送,但此之后发生此错误

时间:2019-06-17 06:58:49

标签: javascript node.js nexmo

  

未捕获的异常回调不是函数{“ stack”:“ TypeError:   回调不是回调函数\ n   (/home/akkastech/backend-api/node_modules/nexmo/src/index.js:171:23)\n   在HttpClient.callback [作为__parseResponse]   (/home/akkastech/backend-api/node_modules/nexmo/src/HttpClient.js:181:7)\n   在IncomingMessage处。__parseResponse   (/home/akkastech/backend-api/node_modules/nexmo/src/HttpClient.js:93:16)\n   在emitNone(events.js:111:20)\ n在IncomingMessage.emit   (events.js:208:7)\ n在endReadableNT   (_stream_visible.js:1055:12)\ n在_combinedTickCallback   (internal / process / next_tick.js:138:11)\ n在process._tickCallback   (internal / process / next_tick.js:180:9)“}

1 个答案:

答案 0 :(得分:2)

看起来您正在传递某些内容作为实际上不是函数的回调参数。它应该看起来像这样:

nexmo.message.sendSms(from, to, text, (err, responseData) => {
    if (err) {
        console.log(err);
    } else {
        if(responseData.messages[0]['status'] === "0") {
            console.log("Message sent successfully.");
        } else {
            console.log(`Message failed with error: ${responseData.messages[0]['error-text']}`);
        }
    }
})