Manuel Reis Manuel Reis - 8 months ago 69
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