有没有办法知道在 `Promise.join` 中哪个 promise 失败了?

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

在下面的代码中(使用 Bluebird 库),有没有办法在出错的情况下确定哪个 promise 失败了?

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

这两个承诺都会在拒绝时产生一般错误消息。

你不能。如果你真的需要,你必须为每个单独实现一个错误处理程序。

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
});