Manuel Reis Manuel Reis - 17 days ago 7
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

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

Promise.join(User.getByName(username)
    .catch(err => {throw new Error('error in getByName');}), 
  User.getByKey(key)
    .catch(err => {throw new Error('error in getByKey');}),
 (user1, user2) => {
  //do operations
}).catch((error) => {
  // error.message should now display origin of error
});