I wanna catch some status responses in my failure part of my Alamofire request.
The following code:
let URL = "https://api.foo.bar"
Alamofire.request(URL, method: .post, parameters: parameters).responseObject { (response: DataResponse<UserResponse>) in
switch response.result {
case .success:
// Yea, it worked.
case .failure(let error):
print(error)
}
if let httpStatusCode = response.response?.statusCode {
switch(httpStatusCode) {
case 418:
let alert = UIAlertController(title: "Whoops", message: "I't s a Teapot.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
break
default:
print("DEFAULT...")
break
//
}
}
}
Returns for some reason a 500 error, but that's not from the API, but from the code itself, but where is it causing it? I can't figure out how to get the Status code
responses correctly.