I'm running into a new issue with regards to returning an error from a remoteMethod that sends an email; see code below:
// Send email
Mail.send = function (options, cb) {
// Pass email through to loopback's built-in email model
loopback.Email.send(options, function(err, result) {
// Return on error
if (err) return cb(err);
// Callback result
cb(null, result);
});
};
When an error is returned from loopback.Email.send it's being returned with return cb(err); however it's being returned from loopback with an HTTP status of 200 so Angular is not seeing it as an error. In all my other remoteMethods this error handling signature works just fine. Is there something different about how loopback.Email.send is returning errors? I've noticed if I wrap the error in a new Error(err) statement it works correctly. I know that loopback.Email is using Nodemailer; could that be the issue?
Lastly I'm using the Mandrill loopback connector (
https://www.npmjs.com/package/lb-connector-mandrill) could that maybe be the issue?
What I'd like to know is if the error handling signature used above is correct, or if I should get in the habit of wrapping errors in a "new Error('error msg')" block? Any advice is appreciated!