title: Error handling in swift 3 using objectMapper and alamofire
body: <p>How i can handle error in completion block if get error from server side.Here is object mapper class for login.</p>
  
  <pre><code>  class Login: Mappable {
  var result: LoginData?
  var success: Bool?
  var error: String?
  
  required init?(map: Map){
  
  }
  
  func mapping(map: Map) {
  
      result &lt;- map["data"]
      success &lt;- map["success"]
      error &lt;- map["error"]
  
  }
  }
  
  class LoginData: Mappable {
  var name: String?
  var title: String?
  var token: String?
  var imageUrl: String?
  
  required init?(map: Map){
  
  }
  
  func mapping(map: Map) {
  
      name &lt;- map["name"]
      title &lt;- map["title"]
      token &lt;- map["token"]
      name &lt;- map["name"]
      imageUrl &lt;- map["imageUrl"]
  }
  }
  </code></pre>
  
  <p>Here is my api calling from view controller.</p>
  
  <pre><code>   func loginMethod(){
      let postData = ["username":loginDict.object(forKey: KUserUserId) as! String,
                      "password": loginDict.object(forKey: KUserPass) as! String]
  
      userLoginHttp(parameters: postData){ completion in
          self.getUserLoginResponse(result: completion)
      }
  }
  
  func getUserLoginResponse(result: LoginData) {
   // Here i do further
  }
  </code></pre>
  
  <p>This is Network class mthod from where i fire the service</p>
  
  <p>//User login web service</p>
  
  <pre><code>func userLoginHttp(parameters:Parameters, completion:@escaping (_  
   result:LoginData)-&gt;()) {
  let defaultObject = UserDefaults.standard
  var headerToken = String()
  if let x = defaultObject.object(forKey: KDeviceToken)
  {
    headerToken = x as! String
  }
  else{
      headerToken = ""
  }
  
  let headers = ["fcmToken": headerToken]
  
  Alamofire.request(KLoginUrl, method: .post, parameters: parameters,encoding: JSONEncoding.default, headers: headers)
      .validate()
      .responseObject{ (response: DataResponse&lt;Login&gt;) in
          switch response.result{
          case .success:
              let value = response.result.value
              completion((value?.result)!)
          case .failure(let error):
              print(error.localizedDescription)
          }
  }
  }
  </code></pre>
  
  <p>So how i can handle error in my view controller completion block?</p>