Skip to content

SDK crashed in case of network error #47

Closed
@endrelovas

Description

@endrelovas

All kind of endpoint queries have one basic bug within BAAClient.m
getPath, postPath, putPath, deletePath tries to convert empty (nil) response to NSDictionary which causes the SDK to crash immediately.

This part:

    [[self.session dataTaskWithRequest:request
                     completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

                         NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
                         NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data
                                                                                    options:kNilOptions
                                                                                      error:nil];

It should investigate the error return with the completionHandler prior to convert JSON to NSDictionary.
Something like this (not a full code, never tested)

    [[self.session dataTaskWithRequest:request
                     completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                         if (error) {
                             failure(error);
                             return;
                         }

                         NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
                         NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data
                                                                                    options:kNilOptions
                                                                                      error:nil];

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