Manuel Reis Manuel Reis - 1 year ago 100
Node.js Question

Is there a way to know which promise fail in a `Promise.join`?

In the following code (using the Bluebird library), is there a way, in case of error, to determine which of the promises failed?

Promise.join(User.getByName(username), User.getByKey(key), (user1, user2) => {
//do operations
}).catch((error) => {
//How to know which failed?

Both of these promises produce generic error messages on reject.

Answer Source

You cant. If you really have to, you have to implement an error handler for each individually.

    .catch(err => {throw new Error('error in getByName');}), 
    .catch(err => {throw new Error('error in getByKey');}),
 (user1, user2) => {
  //do operations
}).catch((error) => {
  // error.message should now display origin of error
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download