I have the following code in my service
myService.ts
makeHttpGetRequest(url){
return Observable.interval(config.SUPERVISOR_REFRESH_INTERVAL * 1000)
.switchMap(() => this.http.get(url))
.map(res => res.json())
.timeout(config.REQUEST_TIMEOUT * 1000, new Error('Time out occurred'))
}
In my component file,
myComponent.ts
ngOnInit(){
this._myService.makeHttpGetRequest(myurl)
.subscribe(
data => {
this.supervisorServers = data;
}
},
error => {
this.error = true;
console.log(error); //gives an object at this point
this.showError(error);
}
);
}
I want to print the error message in case of for e.g. Invailid url. When I print the error, I get an object (probably response object) like the following:
Object { _body: error, status: 200, statusText: "Ok", headers: Object, type: 3, url: null }
If I open this, I cannot find the error message. Is there a better way to get precies error messages?