0

I have this error :

TypeError: NetworkError when attempting to fetch resource.

when I tried to fetch data from a server. and I don't know why...

My code :

getListApps: async function () {
             let url = `${SA_BASE_URL}/applications`;

            // Set headers
            let headers = new Headers();
            headers.append('Access-Control-Allow-Origin', '*');
            headers.append('Access-Control-Allow-Methods', 'GET');
            headers.append('Access-Control-Allow-Credentials', true);
            headers.append('Authorization', 'Basic ' + btoa(SA_LOGIN + ":" + SA_PASSWORD));

            try {
                // GET request
                const response = await fetch(url, { method: 'GET', headers: headers, mode: 'no-cors' });
                if (response.ok) {
                    const data = await response.json();
                    this.listApp = data;
                    this.listApp.forEach(app => {
                        if (app.status === "DISCONNECTED") {
                            this.listDecApp.push(app);
                        }
                    });
                    this.nbr = this.listDecApp.length;
                } else {
                    if (response.status === 400) this.errors = ['Invalid app_permissions value'];
                    if (response.status === 401) this.errors = ['Acces denied'];
                }
            } catch (error) {
                console.log(error);
                this.errors = ["Une erreur est survenue lors de la récupération des informations sur le serveur."]
            }
}

On Firefox and chrome and I don't have any cors plugin anywhere.

j08691
  • 190,436
  • 28
  • 232
  • 252

0 Answers0