title: Why is XMLHttpRequest.onerror invoked when the web request actually succeded?
body: <p>I am using the following little gem within the background script of a Mozilla webextension:</p>
  
  <pre><code>function makeRequest(url) {
      return new Promise(function(resolve,reject) {
              console.log("begin makeRequest");
              var xhr = new XMLHttpRequest();
              xhr.open('GET', url);
              xhr.onload = function() {
                      if (this.status &gt;= 200 &amp;&amp; this.status &lt; 300) {
                              console.log("resolve makeRequest");
                              resolve(xhr.response);
                      } else {
                              console.log("reject makeRequest");
                              reject({
                                      status: this.status,
                                      statusText: xhr.statusText
                              });
                      }
              }
              xhr.onerror = function() {
                      console.log("reject makeRequest by error");
                      reject({
                              status: this.status,
                              statusText: xhr.statusText
                      });
              }
              xhr.send(null);
              console.log("makeRequest sent");
      });
  }
  </code></pre>
  
  <p>I invoke this with a line like  <code>makeRequest("http://www.example.com")</code> and I can verify from the Apache access log at www.example.com, that the request succeeds (status code "200"). In particular, this makes me confident that the request does not fail due to some misisng permissions in the manifest or the like. Consequently, I'd expect the <code>xhr.onload</code> to be invoked with <code>this.status == 200</code>.
  But instead of this, the <code>xhr.onerror</code> is invoked, i.e., the console log reads</p>
  
  <pre><code>begin makeRequest
  makeRequest sent
  reject makeRequest by error
  </code></pre>
  
  <p>Why? (As in : How is this even possible?)</p>