Error getting data

Hi guys,

I’m new at Ionic framework and I have a very weird problem. I have a web site based on Angular and the backend is NodeJS. The website works fine.

In ionic 3 I’m trying to get data from the same API. Sometimes I get the data and sometimes I get the following error:

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined

The following code is


getRemoteData():Observable<ProductInterface[]> {
let header = new HttpHeaders({ 'Content-Type': 'application/json', 'x-access-token': this.token });
header.append('Content-Type', 'application/json');
header.append('x-access-token', this.token);
return this.http.get<ProductInterface[]>('api/getallproducts',{ headers: header });


constructor(public navCtrl: NavController, public getData: DataProvider) {
this.getData.getRemoteData().subscribe(data => {this.products = data;});

Guys I need your help. Any suggestions……

Thanks in advance