title: How to figure out the status code for the rejection of the html template in AngularJS?
body: <p>How can I get the status code of the response - <code>401</code> in <code>$routeChangeError</code> and redirect to the correct route with AngularJS if the user is not authorized.</p>
  
  <pre><code>$rootScope.$on("$routeChangeError", function(event, next, current, rejection) {
       var status = //how to get the status code?
       if(status===401) $location.path("/401");
  });
  </code></pre>
  
  <p>I have a the following route :</p>
  
  <pre><code>$routeProvider
      .when("/office/workspaces", {
          templateUrl: "partials/office/workspaces",
          controller: "OfficeWorkspacesCtrl"
      });
  </code></pre>
  
  <p>the following server route:</p>
  
  <pre><code>router.get("/workspaces", Identity.isAuthenticated, function(request, response) {
      response.render("office/workspaces", {});
  });
  </code></pre>
  
  <p>and the following isAuthenticated function:</p>
  
  <pre><code>module.exports.isAuthenticated = function(req, res, next) {
      var isAuthenticated = util.isObject(req.identity);
      if (isAuthenticated) {
          return next();
      } else {
          return res.status(401).send();
      }
   };
  </code></pre>