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

SDK crashes App when empty response delivered by the server #41

Open
hoffmannjoern opened this issue May 20, 2015 · 1 comment
Open

Comments

@hoffmannjoern
Copy link

The + (NSError *)authenticationErrorForResponse:(NSDictionary *)response in BaasBox.m
crashes.

Reason (original code below):

  • (NSError *)authenticationErrorForResponse:(NSDictionary *)response {
    if (response == nil) {
    NSDictionary *errorDetail = @{NSLocalizedDescriptionKey:@"Server returned an empty response.",
    @"BaasBox API Version": @[response[@"API_version"]],
    // ---> KV coding an dictionary cannot save a nil reference and response and so the requested object is nil !!!

                                  @"iOS SDK Version" : VERSION};
    return [NSError errorWithDomain:[BaasBox errorDomain]
                               code:-22222
                           userInfo:errorDetail];
    

    }

    NSDictionary *errorDetail = @{NSLocalizedDescriptionKey:response[@"message"],
    @"BaasBox_API_version": @[response[@"API_version"]],
    @"iOS SDK Version" : VERSION};
    NSError *error = [NSError errorWithDomain:[BaasBox errorDomain]
    code:-22222
    userInfo:errorDetail];
    return error;
    }

Consider the following fix, wich will in addition make the code more compact and readable:

  • (NSError *)authenticationErrorForResponse:(NSDictionary *)response
    {
    NSString *message = response[@"message"] ? response[@"message"] : @"Server returned an empty response.";
    NSString *apiVersion = response[@"API_version"] ? response[@"API_version"] : @"unknown";

    NSDictionary *errorDetail = @{NSLocalizedDescriptionKey:message,
    @"BaasBox API Version": apiVersion,
    @"iOS SDK Version" : VERSION};

    NSError *error = [NSError errorWithDomain:[BaasBox errorDomain]
    code:-22222
    userInfo:errorDetail];
    return error;
    }

@funkyboy
Copy link
Contributor

Thank you for spotting this! We will include a fix in the next version. If you like you can send a PR.

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

2 participants