title: Error handling in Alamofire
body: <p>I have the HTTP code in an AngularJS controller:</p>
  
  <pre><code>$http.post('/api/users/authenticate', {email: $scope.email, password: $scope.password})
      .success(function (data, status, headers, config) {
          authService.login($scope.email);
          $state.go('home');
      })
      .error(function (data, status, headers, config) {
          $scope.errorMessages = data;
          $scope.password = "";
      });
  </code></pre>
  
  <p>In the success case, the server will respond with a JSON representation of a user. In the error case the server will respond with a simple string such as <code>User not found</code> which can be accessed through the <code>data</code> parameter.</p>
  
  <p>I'm having trouble figuring out how to do something similar in Alamofire. Here's what I have right now:</p>
  
  <pre><code>@IBAction func LoginPressed(sender: AnyObject) {
      let params: Dictionary&lt;String,AnyObject&gt; = ["email": emailField.text, "password": passwordField.text]
  
      Alamofire.request(.POST, "http://localhost:3000/api/users/authenticate", parameters: params)
          .responseJSON {(request, response, data, error) in
              if error == nil {
                  dispatch_async(dispatch_get_main_queue(), {
                      let welcome = self.storyboard?.instantiateViewControllerWithIdentifier("login") as UINavigationController;
  
                      self.presentViewController(welcome, animated: true, completion: nil);
                  })
              }
              else{
                  dispatch_async(dispatch_get_main_queue(), {
                      // I want to set the error label to the simple message which I know the server will return
                      self.errorLabel.text = "something went wrong"
                  });
              }
      }
  }
  </code></pre>
  
  <p>I have no idea if I'm handling the non-error case correctly either and would appreciate input on that as well.</p>