mardi 14 juillet 2020

fetch request's http version is undefined. how to fix this?

In my ember app I'm using native Javascript fetch-method (after user clicks login at login-form) to request a POST to a server-endpoint.

    //...
    const options = {
      body,
      headers,
      method: 'POST'
    };

    return new RSVP.Promise((resolve, reject) => {
      fetch(url, options).then((response) => {
        response.text().then((text) => {
          try {
            let json = JSON.parse(text);
            if (!response.ok) {
              response.responseJSON = json;
              reject(response);
            } else {
              resolve(json);
            }
          } catch (SyntaxError) {
            response.responseText = text;
            reject(response);
          }
        });
      }).catch(reject);
    });
    //...

If the ember-app is loaded freshly, the first login-click results in an error. The reason seems to be, that the HTTP-Version is undefined at the error-requests. See: enter image description here ember-server output:

enter image description here

If the app is not loaded freshly, fetch works as expected: enter image description here ember-server output:

enter image description here

What could be the reason that the http-version is undefined? How I can set the HTTP-Version?




Aucun commentaire:

Enregistrer un commentaire