我正在尝试捕获由Angular中的Web API抛出的错误,并希望在某些情况下显示用户友好的错误消息。根据下面的响应正文,我如何访问字符串"PE和所有者签名必须附加到提交的状态“?
{
"data": {
"model.WorkflowStepId": [
"PE and Owner Signature must be attached for a status of Submitted"
]
},
"exceptionType": "FieldValidation"
我使用的是Angular和TypeScript。在API调用的情况下,我使用了try catch结构来处理错误。如果try块中出现任何错误,那么它根本不会去catch块。应用程序仅在那里终止。
我也尝试过使用throw。以下是示例代码片段,
try {
this.api.getAPI(Id).subscribe( // this.api is my api service and getAPI is present there
(data: any) => {
if (data == null) {
throw 'Empty respon