Using Alamofire 4/Swift 3 how can you differentiate between a request that fails due to:
- Network connectivity (host down, can't reach host) vs
- Invalid server HTTP response code (ie: 499) which causes the Alamofire request to fail due to calling
validate()
?
Code:
sessionManager.request(url, method: .post, parameters:dict, encoding: JSONEncoding.default)
.validate() //Validate status code
.responseData { response in
if response.result.isFailure {
//??NETWORK ERROR OR INVALID SERVER RESPONSE??
}
}
We want to handle each case differently. In the latter case we want to interrogate the response. (In the former we don't as there is no response).