In Alamofire calling .validate() does automatic validation and passes status code 200...299 as success.
In case of failed API request server sends status code 400 and some internal error message and code in JSON to identify which kind of error is this. I couldn't find a way to get this JSON data in case status code is 400 under case .Failure in following example:
Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
.validate()
.responseJSON { response in
switch response.result {
case .Success:
print("Validation Successful")
case .Failure(let error):
print(error)
}
}
error doesn't contain response data. Is there anyway to get it?