Last active
August 29, 2015 14:16
-
-
Save aj07mm/036acc6da39f432774bf to your computer and use it in GitHub Desktop.
how to test response in a callback inside a method inside a method?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'sendMail': function(mailBody,maiSubject,mailTo, sendAt){ | |
if(mailTo == 'string'){ | |
mailTo = formatMailTo(mailTo); | |
} | |
var message = { | |
"html": mailBody, | |
"text": mailBody, | |
"subject": maiSubject, | |
"from_email": "[email protected]", | |
"from_name": "foobarsatanico", | |
"to": mailTo | |
}; | |
Mandrill.messages.send({"message": message, "async": false, "send_at": sendAt }, function(result) { | |
console.log(result); | |
return result; | |
}, function(e) { | |
console.log('A mandrill error occurred: ' + e.name + ' - ' + e.message); | |
return e.message; | |
}); | |
} |
Inject a callback an return result.
sendMail: function(mailBody,maiSubject,mailTo, sendAt, callback) {
if(mailTo == 'string'){
mailTo = formatMailTo(mailTo);
}
var message = {
"html": mailBody,
"text": mailBody,
"subject": maiSubject,
"from_email": "[email protected]",
"from_name": "foobarsatanico",
"to": mailTo
};
Mandrill.messages.send({"message": message, "async": false, "send_at": sendAt }, function(result) {
console.log(result);
callback(result);
}, function(e) {
console.log('A mandrill error occurred: ' + e.name + ' - ' + e.message);
callback(e.message);
});
}
OR use Promise. 😃
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The var "e" is a object containing erro occurred.
Mandrill Messages