Javascript 解析云代码Mandrill承诺
因此,我在迁移Mailgun并开始使用Mandrill时遇到了一个问题。我遵循了Parse Purchase应用程序教程,并且有一个非常类似的代码库。以下是它当前的状态并成功运行Javascript 解析云代码Mandrill承诺,javascript,parse-platform,promise,mandrill,parse-cloud-code,Javascript,Parse Platform,Promise,Mandrill,Parse Cloud Code,因此,我在迁移Mailgun并开始使用Mandrill时遇到了一个问题。我遵循了Parse Purchase应用程序教程,并且有一个非常类似的代码库。以下是它当前的状态并成功运行 return Mailgun.sendEmail({ to: currentUser.get('email'), from: hostEmail, subject: 'Your ticket(s) purchase for ' + eventObject.get('title') + ' was
return Mailgun.sendEmail({
to: currentUser.get('email'),
from: hostEmail,
subject: 'Your ticket(s) purchase for ' + eventObject.get('title') + ' was successful!',
text: body
}).then(null, function(error) {
return Parse.Promise.error('Your purchase was successful, but we were not able to send you an email.');
});
因此,这将成功运行,不会引发任何错误
这就是山楂的等价物
return Mandrill.sendEmail({
message: {
text: body,
subject: 'Your ticket(s) purchase for ' + eventObject.get('title') + ' was successful!',
from_email: hostEmail,
from_name: appname,
to: [{
email: currentUser.get('email'),
name: currentUser.get('displayName')
}]
},
async: true
}).then(null, function(error) {
console.log('Sending email failed. Error: ' + error);
return Parse.Promise.error('Your purchase was successful, but we were not able to send you an email.');
});
显然,这是行不通的
错误日志显示:
Error: TypeError: Cannot read property 'success' of undefined
at Object.exports.sendEmail (mandrill.js:55:21)
at main.js:115:25
at e (Parse.js:2:6670)
at Parse.js:2:6119
at Array.forEach (native)
at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:661)
at c.extend.resolve (Parse.js:2:6070)
at Parse.js:2:6749
at e (Parse.js:2:6670)
at Parse.js:2:6119 (Code: 141, Version: 1.6.0)
因此,我认为Mandrill成功发送电子邮件是因为它搜索了“success”属性,但承诺总是失败,并将错误响应返回到iOS应用程序
任何帮助都将不胜感激
再次感谢找到了问题。显然,您必须实际声明一个promise变量并将成功/失败回调发送给它 我在评论中发布的要点链接帮助了我 这就是我现在要做的
Parse.Cloud.define('purchase', function(request, response) {
...
...
...
var message = {
text: body,
subject: 'Your ticket(s) purchase for ' + eventObject.get('title') + ' was successful!',
from_email: hostEmail,
from_name: appname,
to: [{
email: currentUser.get('email'),
name: currentUser.get('displayName'),
}]
};
return sendMandrillEmailPromise(message).then(null, function(error) {
console.log('Sending email failed. Error: ' + error);
return Parse.Promise.error('Your purchase was successful, but we not able to send you an email');
...
...
...
});
var sendMandrillEmailPromise = function(message){
var promise = new Parse.Promise();
Mandrill.sendEmail({
message: message,
async: true,
},{
success: function(httpResponse) {
promise.resolve(httpResponse);
},
error: function(error) {
promise.error(error);
}
});
return promise;
}
工作如预期,我收到了一封很棒的电子邮件!谢谢大家的意见 你确定Mandrill支持承诺吗?它似乎在寻找
成功
回调。您真的想要异步:false
?@Bergi不,我不想要。那是我的错,哈哈。这将基本上停止整个服务器,直到进程完成。那太糟糕了!是这样吗?他们为什么要给我们这个选择?@Bergi,我在这里找到了一个链接,将承诺与Mandrill sendMail集成在一起。我会发布一个editAh好吧,我认为这是一个答案,而不是一个编辑…你可能想向Mandrill提交一份bug报告,当然,他们是否会支持开箱即用的承诺:-)听起来像是一个计划!行