0

I'm trying to create a mobile application with API Connection to the database. Sometimes I'm not getting any error and it all works fine with the API but usually, I get this kind of error. (See picture below)

This is the error I got from the Dev Tools

Here is my code:

let headers = new Headers ({
  'Accept' : 'application/json',
  'Authorization' : 'Bearer ' + this.token
});
let options = new RequestOptions({ headers : headers });

return new Promise((resolve, reject) => {
  this.http.get('https://mywebsite.com/api',  options)
  .toPromise()
  .then((response) =>
  {
    if(response){
      console.log('API Response : ', response.json());
      var _response = response.json();

      resolve(response.json());
    }
    this.loadingSrvc.hide();
  })
  .catch((error) =>
  {
    this.loadingSrvc.hide();
    if(error){
      console.error('API Error : ', error.status);
      console.error('API Error : ', JSON.stringify(error));
      reject(error.json());
    }
  });
});

I'm using Ionic CLI PRO v4.2.1 and MySQL--phpMyAdmin for database

My main dilemma is that sometimes it works and sometimes it doesn't and I don't even know the reason.

Oliver Primo
  • 317
  • 4
  • 18

0 Answers0