remoteMethod Error Handling

57 views
Skip to first unread message

Charles Naccio

unread,
Mar 30, 2015, 2:23:37 PM3/30/15
to loopb...@googlegroups.com
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!

Charles Naccio

unread,
Mar 30, 2015, 2:30:39 PM3/30/15
to loopb...@googlegroups.com
I just noticed that the Mandrill loopback connector uses promises for it's send function; could this be the issue?
Reply all
Reply to author
Forward
0 new messages