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

status code: 404,but response.result = SUCCESS #895

Closed
hengchengfei opened this issue Oct 27, 2015 · 3 comments
Closed

status code: 404,but response.result = SUCCESS #895

hengchengfei opened this issue Oct 27, 2015 · 3 comments

Comments

@hengchengfei
Copy link

1

@cnoon
Copy link
Member

cnoon commented Oct 27, 2015

You aren't validating the response status code, so it is possible that a 404 will return you a .Success case. All that the responseData serializer does is validate that there wasn't an error (which there won't be since you aren't validating the response status code) or that the data exists.

public static func dataResponseSerializer() -> ResponseSerializer<NSData, NSError> {
    return ResponseSerializer { _, _, data, error in
        guard error == nil else { return .Failure(error!) }

        guard let validData = data where validData.length > 0 else {
            let failureReason = "Data could not be serialized. Input data was nil or zero length."
            let error = Error.errorWithCode(.DataSerializationFailed, failureReason: failureReason)
            return .Failure(error)
        }

        return .Success(validData)
    }
}

In your case, you are receiving a 404 which isn't throwing an error, and the server is returning data. Therefore, your responseData serializer succeeds. If you expect a 404 to always throw an error, you should additionally use the .validate(statusCode: [200]) method before the responseData serializer. More info in the Validation Section of the README.

In the future, questions like this are better suited for Stack Overflow with an alamofire tag. We use GitHub for bugs and feature requests. 🍻


From our Contribution Guidelines

Asking Questions

We don't use GitHub as a support forum. For any usage questions that are not specific to the project itself, please ask on Stack Overflow instead. By doing so, you'll be more likely to quickly solve your problem, and you'll allow anyone else with the same question to find the answer. This also allows maintainers to focus on improving the project for others.

@hengchengfei
Copy link
Author

I really appreciate

@stevekim0417
Copy link

I am struggling with this issue... Thanks you so much.

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

No branches or pull requests

3 participants