如何从BaseController派生类返回错误消息



是否有一种方法可以从BaseController派生类向客户端返回自定义错误消息,例如:

NotFound("Function :" + scheduleReq.UserFunction + " for date: " + scheduleReq.Date + " already taken");

不幸的是,NotFound返回值并没有将我的消息传达给客户端。我想在error变量中获得我的消息,如下所示:

客户:

this.accountService.GetScheduleFromPool(this.account.id, schedule)
.pipe(first())
.subscribe({
next: (account) => {
this.addingSchedule = false;
console.log(account);
this.schedules = account.schedules;

if (this.poolElements.length != 0) {
this.form.get('availableScheduledDate').setValue(this.poolElements[0].date);
this.form.get('availableFunction').setValue(this.poolElements[0].userFunction);
}
this.updateSchedulesAndPoolFromServer();
},
error: error => {
this.addingSchedule = false;
this.alertService.error(error);
}
});

您可以通过在基类的派生类中覆盖任何成员类来扩展其功能。

最新更新