Я не совсем уверен, где этот код будет использоваться в вашей кодовой базе, но вы можете внести эти изменения
Функция delayRejectFunction
// Promise which gets rejected
const delayRejectFunction = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
const id = Math.floor((Math.random() * 10) + 1)
reject({
userid: id,
isSuccess: false
})
}, 100)
})
}
Вызов функции delayRejectFunction
// statement is not executed because error is thrown
promiseArray.push(delayRejectFunction().then((response) => {
userId = response.userId
return { ...user,
userId
}
}).catch(err => {
userId = err.userid
isSuccess = err.isSuccess
return { ...user,
userId,
isSuccess
}
}));