title: Angular 2 REST request HTTP status code 401 changes to 0
body: <p>I'm developing an Angular2 application.  It seems when my access-token expires the 401 HTTP Status code gets changed to a value of 0 in the Response object.  I'm receiving 401 Unauthorized yet the ERROR Response object has a status of 0.  This is preventing me from trapping a 401 error and attempting to refresh the token.  What's causing the 401 HTTP status code to be changed into HTTP status code of 0?</p>
  
  <p>Here's screenshot from Firefox's console:</p>
  
  <p><a href="https://i.stack.imgur.com/cgGQv.png" rel="noreferrer"><img src="https://i.stack.imgur.com/cgGQv.png" alt="enter image description here"></a></p>
  
  <p>Here's my code:</p>
  
  <pre><code>get(url: string, options?: RequestOptionsArgs): Observable&lt;any&gt; 
  {
      //console.log('GET REQUEST...', url);
  
      return super.get(url, options)
          .catch((err: Response): any =&gt;
          {
              console.log('************* ERROR Response', err);
  
              if (err.status === 400 || err.status === 422)
              {
                  return Observable.throw(err);
              }
              //NOT AUTHENTICATED
              else if (err.status === 401)
              {                   
                  this.authConfig.DeleteToken();
                  return Observable.throw(err);
              }               
              else
              {
                  // this.errorService.notifyError(err);
                  // return Observable.empty();
                  return Observable.throw(err);
              }
          })
          // .retryWhen(error =&gt; error.delay(500))
          // .timeout(2000, new Error('delay exceeded'))
          .finally(() =&gt;
          {
              //console.log('After the request...');
          });
  }
  </code></pre>
  
  <p>This code resides in a custom http service that extends Angular2's HTTP so I can intercept errors in a single location.</p>
  
  <p>In Google Chrome, I get this error message:</p>
  
  <p>XMLHttpRequest cannot load <a href="https://api.cloudcms.com/repositories/XXXXXXXXXXXXXXXX/branches/XXXXXXXXXXXXXXXX/nodesXXXXXXXXXXXXXXXX" rel="noreferrer">https://api.cloudcms.com/repositories/XXXXXXXXXXXXXXXX/branches/XXXXXXXXXXXXXXXX/nodesXXXXXXXXXXXXXXXX</a>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://screwtopmedia.local.solutiaconsulting.com" rel="noreferrer">http://screwtopmedia.local.solutiaconsulting.com</a>' is therefore not allowed access. The response had HTTP status code 401.</p>
  
  <p>This is confusing because I am including 'Access-Control-Allow-Origin' header in request.</p>
  
  <p>Here's a picture of results received in Google Chrome:</p>
  
  <p><a href="https://i.stack.imgur.com/B4sb7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/B4sb7.png" alt="enter image description here"></a></p>
  
  <p>I've tried accessing 'WWW-Authenticate' Response Header as a means to trap for 401.  However, the following code returns a NULL:</p>
  
  <pre><code>err.headers.get("WWW-Authenticate")
  </code></pre>
  
  <p>It's puzzling that I'm getting a CORS issue because I'm not getting any CORS errors when a valid access token is provided.</p>
  
  <p>How do I trap for 401 HTTP status code?  Why is 401 HTTP status code being changed to 0?</p>
  
  <p>Thanks for your help.</p>