title: Alamofire: handle error with success response
body: <p>Hi i am still new to Alamofire and json. i just want to ask on how to handle error on success response. Below is the response of the api with post request.</p>
  
  <pre><code>{
  data =     {
      "cabinet_id" = 3289146811;
      "created_at" = "2018-04-11T04:53:43.288023001Z";
      "user_id" = 123abc;
  };
  }
  </code></pre>
  
  <p>but sometimes i got response as below due to server error</p>
  
  <pre><code>{
  error =     {
      "http_status_code" = 400;
      message = "Unable to proceed";
      type = "rent_request_failed";
  };
  }
  </code></pre>
  
  <p>here is what i have did</p>
  
  <pre><code>let url = "myurl"
  let parameters = ["user_id": ""\(self.idPassed)"",
                            "cabinet_id": "\(self.stringPassed)"]
  
          Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding.default).responseJSON { response in
  
                  if (response.result.isSuccess){
  
                      if let value = response.result.value {
  //now success or failed always navigate to here                            
  Helper.helper.switchToNavigationViewController(Navigation: "hundredpercent")
                          print(value)
  
                      }
                  //do your json stuff
                  } else if (response.result.isFailure) {
                  //Manager your error
                  switch (response.error!._code){
                  case NSURLErrorTimedOut:
                  //Manager your time out error
                  break
                  case NSURLErrorNotConnectedToInternet:
                  //Manager your not connected to internet error
                  break
                  default:
                      let alertt = UIAlertController(title: "Server Error!", message: "Please try again", preferredStyle: .alert)
  
                      alertt.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {(action:UIAlertAction!) in
  //need navigate here if error                        
  Helper.helper.switchToNavigationViewController(Navigation: "qrcodescan")
  
                      }))
  
                      self.present(alertt, animated: true)
                  }
                  }
          }
  </code></pre>