title: Correct method to Redirect from $http.post in angularjs
body: <p>Can you tell me what is the correct way to redirect to another page if $http.post returns a specific error code.</p>
  
  <p>Just to add context, I want to redirect to another page if the user is not logged in or authorized to use the API.</p>
  
  <pre><code>  function getData(filter) {
       var deferred = $q.defer();
       var data = JSON.stringify(filter);
  
        $http.post('/myapp/api/getData', data)
           .success(function (data, status, headers, config) {
              deferred.resolve(data);
           })
                .error(function (error) {
                   deferred.reject(error);
                });
  
       return deferred.promise;
    }
  </code></pre>