【发布时间】:2019-07-16 17:57:26
【问题描述】:
我试图在 Angular 中捕获我的 Web API 引发的错误,并且我想在某些情况下显示用户友好的错误消息。鉴于下面的响应正文,我将如何访问字符串“必须附加 PE 和所有者签名以获得已提交状态”?
{
"data": {
"model.WorkflowStepId": [
"PE and Owner Signature must be attached for a status of Submitted"
]
},
"exceptionType": "FieldValidation"
}
这是我目前所拥有的,但我被卡住了,因为我目前只显示字符串“model.WorkflowSetId”。
this.spinner = this.certService.updateCert(this.damId, this.certId, this.model)
.subscribe(response => {
...
},
(errorRes: HttpErrorResponse) => {
if (errorRes.error && errorRes.error.exceptionType === 'FieldValidation') {
const errors = errorRes.error.data;
for(let error in errors)
this.notificationService.error(error);
} else {
console.log(errorRes);
this.notificationService.error('An unknown error has occurred. Please try again.');
}
});
【问题讨论】:
标签: json angular typescript error-handling