Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the Alamofire NSError #59

Closed
manuelvanrijn opened this issue Dec 3, 2015 · 6 comments
Closed

Getting the Alamofire NSError #59

manuelvanrijn opened this issue Dec 3, 2015 · 6 comments

Comments

@manuelvanrijn
Copy link

I'm unable to fetch the Alamofire response error when making a request.

The only error I am able to retrieve is the error
The operation couldn’t be completed. ObjectMapper failed to serialize response.

i'm using version: 2.1

    Alamofire.request(.GET, url, parameters: nil, encoding: .JSON)
            .responseArray { (response: Response<[MyModel], NSError>) in

                if let error = response.result.error {
                    print("Error: \(error.localizedDescription)")
                    errorBlock(error)
                    return
                }

                completionBlock(response.result.value!)
        }
@denniseffing
Copy link

I got the exact same problem, also using version 2.1.

Is there any update on this?

@tristanhimmelman
Copy link
Owner

I'm not sure why this would be happening...

See the two Response serializers below (they both return the Alamofire error immediately if it exists):
https://github.com/tristanhimmelman/AlamofireObjectMapper/blob/master/AlamofireObjectMapper/AlamofireObjectMapper.swift#L38
https://github.com/tristanhimmelman/AlamofireObjectMapper/blob/master/AlamofireObjectMapper/AlamofireObjectMapper.swift#L107

What kind of error are you expecting to see that is not returned?

You might want to inspect the NSHTTPURLResponse (response.response) to get the statusCode and NSData that was returned from the request

@AlejandroOrozco
Copy link

Yeah i have the same problem, it only retrieves the error of "The operation couldn’t be completed. ObjectMapper failed to serialize response". Could it be posible that the callback is retrieving the success or the failure of the objectmapper action
instead of the request?

By example, at a service is retrieving me 500 status error code but the function keeps going to the success case.

captura de pantalla 2016-01-04 a las 6 14 58 p m

Is there any other way to get the status code or the error message?

@tristanhimmelman
Copy link
Owner

After some research it turns out this is a feature of Alamofire. To get the error, you need to call the validate() function on the request. See the Alamofire docs: https://github.com/Alamofire/Alamofire#validation

@AlejandroOrozco
Copy link

Thank so much, now it works as expected.

@santhoshs5
Copy link

I am having the same issue i could not retrive the status as expected.

Alamofire.upload(data!, with: (myrouter)
.uploadProgress { progress in // main queue by default
// print("Upload Progress: (progress.fractionCompleted)")
}.validate()
.responseJSON { [weak self] response in{

// what can i put here so that i can retrive the status code like 200 or 500
NSURLErrorCannotFindHost
NSURLErrorNetworkConnectionLost

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants