我有一个在C#后端上运行的API调用,但是Angular前端似乎将C#答复视为错误。请注意,对象的文本为“已添加注释”,表示已发回200 OK响应。为什么catchError函数会触发?
C#方法:
[HttpPost("AddComments")]
public actionResult<string> AddComment(BillingComments b)
{
try
{
return StatusCode(200,"comment added");
}
catch (Exception e)
{
return StatusCode(500,"error adding comment");
}
}
角度方法:
submitComment(newComment: BillingComments): any {
return this.http.post('/api/BillingLg/AddComments',newComment)
.pipe(catchError(this.appSvc.handleError<string>('submitComment','comment submitting err')));
}
appSvc.handleError返回的错误:
服务错误:submitComment失败 消息:http://localhost:49975/api/BillingLg/AddCommentsStatus解析期间的Http错误:200详细信息:{“错误”:{},“文本”:“添加了注释”}文本:确定并指定了返回类型(正常失败)