title: AngularJS promise catch 401
body: <p>I am using a very basic angularJS code for a user login like this:  </p>
  
  <pre><code>[...]
  this.login = function(email, password) {
      promise = $http.post('/login',
              {
                  'email': email,
                  'password': password
              });
      promise.then(function(response){
              console.log("success");
          }).catch(function(response){
              console.log("catch");
          }).finally(function(response){
              console.log("finally");
          });
      return promise;
  };
  [...]
  </code></pre>
  
  <p>When the REST API generates an response with code 200, then the client console will log <code>success finally</code> and the user is logged in.<br>
  When the server generates a response with a 403 or 500 code, the console will print out <code>catch finally</code>.  </p>
  
  <p>But when the response will be with a 401, angular does not print out anything. The console will stay empty, only with the <code>POST http://127.0.0.1/login 401 (Unauthorized)</code> hint. But no <code>success</code> or <code>catch</code> as output. And no <code>finally</code> neither.  </p>
  
  <p>In my project, 403 will be catched globally with a <code>$rootScope.$on('event:auth-forbidden', function(r) {...});</code>. That's why the REST Server will only throw 404 when something is not found, 403 when the user has no permission and/or is not logged in and 401 only if the login failed.  </p>
  
  <p>So how can I catch a 401 on <code>$http</code>?<br>
  Isn't the <code>.then</code> promise only for return 200 and the <code>.catch</code> for every other return != 200?  </p>
  
  <p>I am using angularJS v1.6.4 with angular-http-auth v1.5.0.</p>