title: How to define an error callback in AngularJS?
body: <p>In my <code>Controller</code>:</p>
  
  <pre><code>function login(credentials) {
    AuthService
      .login(credentials)
      .then(successCallback, errorCallback);
      //same issue with .then(successCallback).catch(errorCallback);
  }
  
  function successCallback() {
    // do something after success
  }
  
  function errorCallback(data) {
    // do something after error
  }
  </code></pre>
  
  <p>and in my <code>AuthService</code>:</p>
  
  <pre><code>authService.login = function (credentials) {
    return $http
      .post(ENV.apiEndpoint + 'api/v1/login_check', credentials)
      .then(
         function (result) {
          Session.create(result.data.token, result.data.data);
         },
         function (data) {
          Messages.create('Login failed: ' + data.statusText);
         }
      );
  }
  </code></pre>
  
  <p>When my <code>POST</code> delivers a 200 response code, everything works as expected <code>do something after success</code> is executed.</p>
  
  <p>But when my POST results e.g. in a 401 I can see that Messages.create is called (so in this case it enters the <code>error</code> path), but unfortunately my Controller calls the <code>successCallback</code> and not the <code>errorCallback</code>.</p>
  
  <p>I had to migrate this because I was using the deprecated and since Angular 1.6 removed <code>.success</code> and <code>.error</code> promise attributes. It was working back then, but after migration this doesn't work anymore.</p>
  
  <p>What am I doing wrong here?</p>