我使用的是Angular 6,并且非常新。 问题: -我正在发送包含数据的发布请求,该请求应返回验证失败(状态码400和某些响应对象)。 -在错误对象中-我得到的是字符串“ OK”,而不是错误对象。我需要该对象来获取响应-验证失败消息。例如该消息类似于以下内容: {“有效:假”,“原因:重复数据”}。
我还在chrome中检查了网络标签,发现当我发送发布请求时,它实际上发送了2个请求-1-选项,2-发布
我尝试了CatchError方法和throwError,但是我只得到“ OK”错误。
test.Service.ts:
postData(body){
return this.http_client.post<any>(url, body);
}
test.component.ts
this.testService.postData(this.post_data).subscribe(
data => this.CallSuccess(),
error => console.log(error) /* this returns "OK" */
);
我希望错误响应是一个对象而不是字符串。与标题有关吗?