StackThis
StackThis

Reputation: 883

Bluebird catch err logging syntax?

What is the equivalent Bluebird promise err logging to this:

    if (err) {
        console.log(err);
        res.send(err);
    }

For this:

}).catch(Promise.OperationalError, function(e){
    // handle error in Mongoose save findOne etc, res.send(...)
}).catch(function(e){
    // handle other exceptions here, this is most likely
    // a 500 error where the top one is a 4XX, but pay close
    // attention to how you handle errors here
});

Upvotes: 0

Views: 501

Answers (1)

Benjamin Gruenbaum
Benjamin Gruenbaum

Reputation: 276356

Bluebird will automatically log unhandled rejections for you. If you wish to send a server response on an error and mark the chain as handled you can do:

.catch(function(err){
     console.log(err);
     res.send(err);
     throw err; // this is optional, if you don't want to mark the chain as handled.
 });

Upvotes: 2

Related Questions