Skip to content

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

@dexcell

Description

@dexcell

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions