I have a loadSize() func in my angular2 project and it calls a getTotalNumberCampaigns() in my service and return a observable. and I subscribe to this observable to get the result.
this is my loadSize()
loadSize() {
this.campaignsService.getTotalNumberCampaigns().subscribe(value => {//async call
this.campaignSize = value;
}, (err)=> {}
);
}
let's say there is an error with my getTotalNumberCampaigns() and it will fire the err=>{} in subscribe. My question is how do i know what the httpreponse status code is so that i can direct the user to take different action (if it is connection failed(502), the user should refresh. if it is access_token expiry(500), the page should be jump to login page)
this is my getTotalNumberCampaigns in service class
getTotalNumberCampaigns(): Observable<number> {
return this.http.get(`${this.apiUrl}/Count`, { headers: this.headers })
.map<number>(res => <number>res.json())
}