I am developing ionic app for android. I am making http request globally and based response I am processing that request to page. Example, If response not contains auth key in header I will send error message in globally declared service class.
here page subscriber method-
this.loginService.login(params)
.subscribe(resp => {
//processing response
},
error => {
this.alertService.presentToast(AppConstants.NETWORKERRMSG);
this.loading.dismiss();
}
middle (login-Service)service to call http service-
login(params){
return this.netHelper.post('/method',
{ params } ) }
and global http service method in netHelper class-
post(url: string, params: any) {
var response: any ;
this.http.post<any>(url, params,
{headers})
}).subscribe(data => {
console.log(data.status);
console.log(data);
response = data;
},
error => {
console.log(error.status);
console.log(error.error); // error message as string
console.log(error.headers);
});
return response;
}