gpt4 book ai didi

javascript - 解析云代码 Mandrill Promise

转载 作者:行者123 更新时间:2023-11-30 00:32:01 33 4
gpt4 key购买 nike

所以我在从 Mailgun 迁移并开始使用 Mandrill 时遇到了问题。我遵循了 Parse Purchase 应用程序教程并且拥有非常相似的代码库。这是它目前的样子并且成功运行。

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.');
});

所以这运行成功,没有抛出任何错误。

所以这是 Mandrill 的等价物,

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 成功发送了电子邮件,因为它正在搜索“成功”属性,但 Promise 始终失败并向 iOS 应用程序返回错误响应。

任何帮助将不胜感激!

再次感谢

最佳答案

发现问题。显然,您必须实际声明一个 promise 变量并将成功/失败回调发送给它。

我在评论中发布的要点链接对我有帮助 gist Link

这是我现在做的,

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;
}

按预期工作,我收到了一封很棒的电子邮件!感谢大家的意见!

关于javascript - 解析云代码 Mandrill Promise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29103979/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com