I need the service to return a promise keeping status etc. plus having the response data as object both for success and error callbacks.
Is there a suggested way? This is what I currently do (and works):
return this.http.get(url)
.map(res => this.commonService.extractData(res))
.toPromise()
.catch(res => this.commonService.handleError(res));
CommonService:
extractData(res: Response): Response {
res.data = res.text() ? res.json() : null;
return res;
}
handleError(res: Response): Response {
res.data = res.text() ? res.json() : null;
return Promise.reject(res);
}