How can I read the response body in catch block of angular 2 http request. Following is the code that I have so far:
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));
}
})
}
You can catch error like this below:
return this._http.put(url, data, {headers: this.headers})
.map((response: Response) => response)
.catch((error: Response) => {
console.log(response);
if (error.status < 400 || error.status ===500) {
return Observable.throw(error.json().error || 'Server error');
}
})