tristanhimmelman/AlamofireObjectMapper

Error code

Closed this issue · 2 comments

Hi, I am trying to catch errors such as the unauthorized error 401. I put validate() but I am not able to check the error code. Could you give me an example?

Alamofire.request(.GET, "").validate { (request, response) -> Request.ValidationResult in
        switch response.statusCode
        {
        case 200..<400: return .Success
        case 401: return .Failure(NSError(domain: "your Error-String", code: response.statusCode, userInfo: nil))
        default:        return .Failure(NSError(domain: "your Error-String", code: response.statusCode, userInfo: nil))
        }
}.response {
        ...
}

Thank you!!!