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

SVHTTPRequest should not judge http status code != 200 as NSError, it should handled manually by programmer #47

Open
dexcell opened this issue Apr 23, 2014 · 0 comments

Comments

@dexcell
Copy link

dexcell commented Apr 23, 2014

Reason:
Some API does set HTTP status code to 400, whenever we did not comply with the parameters.

Let's say when we want to login, and the email we put is not a valid format, and the server API end point will return HTTP status code 400 with JSON body containing the error message.

At current code, this will trigger NSError.

A good approach is to let the programmer handle the status code by him/her self.

[[SVHTTPClient sharedClient] POST:@"users/login"
                           parameters:parameters
                           completion:^(id response, NSHTTPURLResponse *urlResponse, NSError *error) {
                                if (error != nil) {
                                    // This error here should be only ios error                                 
                                    // Handle error

                                    return;
                                }                           

                                // HTTP status code should be handled manually by the programmer here                              

                                if (urlResponse.statusCode == 200) {
                                    // Proceed
                                } else {
                                    // Show dialog box to user
                                }
                           }];

To fix this we can remove checking serverError in SVHTTPRequest.m on this function

- (void)callCompletionBlockWithResponse:(id)response error:(NSError *)error 

Thank you

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

1 participant