6

I know this might seem to be a duplicate problem but I search for hours here and didn't fine any solutions working : Here is my problem, when I use my app sometimes request are not working, it comes more often when I run it on a iOS devie (iPhone 5s) than it does on an Android device (One + 5T). When I try to request the api I got the following errors. And : `

[Error] Erreur de récupération des gameCredits – e {headers: t, status: 0, statusText: “Unknown Error”, …}
e {headers: t, status: 0, statusText: “Unknown Error”, url: null, ok: false, …}e
   (fonction anonyme) (cordova.js:1731)
   (fonction anonyme) (main.js:1:97464)
   onInvoke (vendor.js:1:27201)
   run (polyfills.js:3:10150)
   (fonction anonyme) (polyfills.js:3:20246)
   onInvokeTask (vendor.js:1:27117)
   runTask (polyfills.js:3:10845)
   o (polyfills.js:3:7902)
   invokeTask (polyfills.js:3:16825)
   p (polyfills.js:2:27655)
   v (polyfills.js:2:27895)
HttpErrorResponse","message":"Http failure response for (unknown url): 0 Unknown`

I tried the answers I found on the following discuss : - IONIC 3 CORS ISSUE (setting proxy) - CORS error in Ionic 3 (downgrading to UIWebview) - Adding an to everything in my config.xml - I added the headers in my authentification service to make sure they were present - I added the headers to send them back in the API.

Do you guys have any idea of how I can solve this problem?

Here are some examples of my code : This is the post example of how I request my api

    post(url: string, body?: any) {
    return this.checkToken().then(isTokenValide => {

        if (isTokenValide) {
            return this.getToken().then(
                token => {
                    this.headers = this.headers.set('Authorization', 'Bearer ' + token);
                    return this.http.post(this.domain + url, body, { headers: this.headers }).toPromise()
                        .then(response => {
                            let httpResponse = new HttpResponse(response);
                            if (this._checkStatus(httpResponse))
                                return Promise.resolve(response);
                        }).catch(error => {
                            return Promise.reject(error);
                        });
                },
                error => {
                    return Promise.reject(error);
                });             } else {

            if (url == 'auth/login' || url == 'auth/register') {
                const headersLogin = new HttpHeaders({'Accept':'application/json','Content-Type':'application/json'});
                let loginUrl =this.domain +url;

                return this.http.post(loginUrl, body, { headers: headersLogin }).toPromise()
                    .then(response => {

                        let httpResponse = new HttpResponse(response);

                        if (this._checkStatus(httpResponse))
                            return Promise.resolve(response);
                    }).catch(error => {

                        return Promise.reject(error);
                    });
            } else {

                return Promise.reject('token invalide');
            }
        }
    }).catch(error => {

        return Promise.reject(error);
    });
}

My Ionic infos are :

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 8.0.0

local packages:

@ionic/app-scripts : 3.1.6
Cordova Platforms  : browser 5.0.3
Ionic Framework    : ionic-angular 3.9.2

System:

Node : v8.10.0
npm  : 6.1.0
OS   : Linux 4.4

Environment Variables:

ANDROID_HOME : not set

Misc:

backend : pro`
Simon
  • 61
  • 5

0 Answers0