在下面的代码中(使用Bluebird库),如果出现错误,是否有办法确定哪些承诺失败?
Promise.join(User.getByName(username), User.getByKey(key), (user1, user2) => {
//do operations
}).catch((error) => {
//How to know which failed?
});
这两个承诺都会在拒绝时产生一般错误消息。
答案 0 :(得分:1)
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
});