【发布时间】:2015-09-06 02:54:52
【问题描述】:
nodemailer author 明确表示他不支持承诺。我以为我会尝试使用 bluebird,但我的尝试似乎没有发现 Nodemailer 抛出的任何错误:
var nodemailer = require('nodemailer');
var Promise = require('bluebird');
// build the transport with promises
var transport = Promise.promisifyAll( nodemailer.createTransport({...}) );
module.exports = {
doit = function() {
// Use bluebird Async
return transport.sendMailAsync({...});
}
}
然后我通过这样做来调用它:
doit().then(function() {
console.log("success!");
}).catch(function(err) {
console.log("There has been an error");
});
但是,当提供无效的电子邮件时,我会看到:
Unhandled rejection Error: Can't send mail - all recipients were rejected
所以,我的 bluebird 承诺没有捕获 nodemailer 错误。我做错了什么?
【问题讨论】:
-
您没有向我们展示您的整个代码 - 请制作一个重现它的版本 - 另外 - 在哪一行出现未处理的拒绝错误? (您收到此消息的事实表明 bluebird 确实看到了错误。
-
couchbase crud 方法也有同样的问题。
标签: javascript node.js promise bluebird nodemailer