API
add(data) {
return this.httpClient.post<any>('/api/v3/templates', data);
}
Observable
this.templateService.add(obj)
.subscribe(
(response) => {
console.log(reposne)
},
(error) => {
console.log(error)
}
);
我的 Post API 以某些消息作为响应返回错误,因为名称已存在但我无法在错误对象中得到该错误对象,该对象打印到控制台
The object which is printed is
{
error:null
headers:HttpHeaders {normalizedNames: Map(0), lazyUpdate: null,
lazyInit: ƒ}
message:"Http failure response for http://localhost/api/v3/templates:
400 Bad Request"
name:"HttpErrorResponse"
ok:false
status:400
statusText:"Bad Request"
url:"http://localhost/api/v3/templates"
}
由于我的错误对象没有该响应正文,我如何获得我收到的响应消息。