Skip to content

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

@hoffmannjoern

Description

@hoffmannjoern

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions