tristanhimmelman / AlamofireObjectMapper

An Alamofire extension which converts JSON response data into swift objects using ObjectMapper
MIT License
2.66k stars 474 forks source link

How do map the json data if user enter incorrect detail? #123

Closed dineshsharmav2 closed 8 years ago

dineshsharmav2 commented 8 years ago

My concern is that my request implementation with mapping object is working fine when user enter correct credential, but issue come when user enter incorrect details:

My Request to map the objects:

**Alamofire.request(.POST, urlString, parameters: params, encoding: .JSON, headers: headers).responseObject(keyPath: "data") { (response: Response) in {

}**

Below is the JSON response when user entered incorrect credentials: { "success": "false", "message": "The User name or Password is incorrect.", "data": null }

Error when user enter incorrect details: Error : result : FAILURE: Error Domain=com.alamofire.error Code=-6004 "ObjectMapper failed to serialize response." UserInfo={NSLocalizedFailureReason=ObjectMapper failed to serialize response.}

Please guide and suggest according this implementation.

waqqas-imena commented 8 years ago

A similar question has already been asked before. Please read this thread.

You can create a FailableObject<T:Mappable, E:Mappable> where T is the expected type of the response, and E is the expected type of the Error.

dineshsharmav2 commented 8 years ago

Hi waqqas-imena, This is done but this was not easy as I thought. Thanks. Dinesh S