如何在angular 2 http请求的catch块中读取响应体 . 以下是我到目前为止的代码:
requeueTask(data): Observable<Response>{
this.setHeaders();
let url = SharedService.requeueTaskApi;
return this._http.put(url, data, {headers: this.headers})
.map((response: Response) => response)
//.do(data => console.log(JSON.stringify(data)))
.catch((error: any, response) => {
console.log(response);
if (error.status < 400 || error.status ===500) {
return Observable.throw(new Error(error.status));
}
})
}
1 回答
您可以捕获如下错误: