【发布时间】:2020-12-16 23:13:04
【问题描述】:
我使用 Promise.all 进行 api 调用,如下所示:
Promise.all(this.hostName.slice(0, this.Id.length).map((hostName) => {
return this.serviceC.status(hostName)
.then(res => {
return new Promise((resolve, reject) => {
const oretry: ORInterface = {
oQid: res.rows[0].qid,
reason: this.reason
};
this.serviceB.retry(oretry).subscribe(resolve);
});
});
}))
.then(() => {
this.dialog.close();
})
.catch(err => {
console.log(err);
});
上面的代码工作正常。
现在我想在成功完成this.serviceB.retry(oretry) 之后再进行一次api调用。
第二个api是this.serviceB.createDbEntry(sentry)和sentry如下:
const sretry: SDInterface = {
hostName,
Id: this.Id.slice(0, this.Id.length),
reason: this.reason
};
而且,我正在这样做
Promise.all(this.hostName.slice(0, this.Id.length).map((hostName) => {
return this.serviceC.status(hostName)
.then(res => {
return new Promise((resolve, reject) => {
const oretry: ORInterface = {
oQid: res.rows[0].qid,
reason: this.reason
};
const sretry: SDInterface = {
hostName,
Id: this.Id.slice(0, this.Id.length),
reason: this.reason
};
this.serviceB.retry(oretry).subscribe(resolve);
this.serviceB.createDbEntry(sentry).subscribe(resolve);
});
});
}))
.then(() => {
this.dialog.close();
})
.catch(err => {
console.log(err);
});
以上代码报错:
error: "SequelizeValidationError: string violation: Id cannot be an array or an object"
看起来它没有为每个Id调用第二个api
【问题讨论】:
标签: javascript node.js angular promise angular-promise