title: XmlHttpRequest get callback response when request fails
body: <p>I have a simple request I make to my service:</p>
  
  <pre><code> var request = new XMLHttpRequest();
      request.open("OPTIONS", url, true);
      request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
      request.setRequestHeader('Accept', 'application/json');
  
      request.onreadystatechange = function () {
          if (request.readyState != 4) {
              return;
          }
  
          var authType = request.getResponseHeader("WWW-Authenticate");
  
          makeRequest(...);
      };
  
      request.send();
  }
  </code></pre>
  
  <p>So what I'm trying to achieve is make a call to my endpoint to see what's the authorisation type (basic or bearer) and then when I get the auth type I will make the actual request with the proper credentials.</p>
  
  <p>If I make the request manually I get the 401 unauthorised which is normal but I also get the WWW-Authenticate: Basic ... in my headers. However if I do this javascript call it will just fail with 401:unauthorised but I don't get this failed response in my callback so the authType will be undefined.</p>
  
  <p>I haven't used javascript before so the question is how can I get the response in the callback even if the request failed with unAuthorised ?</p>