Async finding object by objectId not working, load failed

I am trying to find an object by it’s objectId.

This code works:

        let dataStore = backendless?.data.ofTable("Workouts")

But it throws an exception if the object does not exist.

So I am trying to use this

 dataStore?.find(byId: id, response: { (wo) in
            print(wo)
            workouts.append(Workout.fromDictToWorkout(wDict: wo! as! [String : Any]))
            }, error: { (error) in
                print(error!)
            })

But it just hangs and then returns this:
2017-08-23 16:00:17.885689-0400 PIT[19987:875840] TIC TCP Conn Failed [2:0x604000174580]: 3:-9802 Err(-9802)

2017-08-23 16:00:17.886198-0400 PIT[19987:875840] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

2017-08-23 16:00:17.886375-0400 PIT[19987:875840] Task <882E0447-F399-40B1-975E-B160F5934638>.<0> HTTP load failed (error code: -1200 [3:-9802])

2017-08-23 16:00:17.886622-0400 PIT[19987:875842] NSURLConnection finished with error - code -1200

What is going on here? Is there a way to just handle the exception that the sync method throws? Why isn’t the async one working?

Hello,

You can catch errors from blocking/synchronous API calls using try/catch as shown in the documentation:
https://backendless.com/docs/ios/doc.html#shared_error_handling

As for the http-related error, are you using our Cloud service or perhaps a private installation of Backendless?

Regards,
Mark

Hi,

That try/ catch worked perfectly! Thank you so much for your speedy help.

And as for the http-related error, I am using your Cloud service.

It is still quite odd that you’re getting that error for the async call. The underlying networking mechanism in our library is the same between sync and async.

I just tried it again for fun and got the same thing:

 dataStore?.find(byId: ids, response: { (wo) in
                print(wo!)
            }, error: { (error) in
                print(error!)
            })

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

2017-08-23 16:46:45.451477-0400 PIT[20654:917222] Task <3B5AC8FF-CF21-4F1B-9712-CB9CCE541B52>.<0> HTTP load failed (error code: -1200 [3:-9802])

2017-08-23 16:46:45.451670-0400 PIT[20654:916812] NSURLConnection finished with error - code -1200

I am running Xcode 9 beta 6 if that means anything to you.

Sorry, I had a typo, I meant this

for id in ids {
            dataStore?.find(byId: id, response: { (wo) in
                print(wo!)
            }, error: { (error) in
                print(error!)
            })
}

2017-08-23 16:50:01.511139-0400 PIT[20770:919422] TIC TCP Conn Failed [2:0x60c00016b1c0]: 3:-9802 Err(-9802)

2017-08-23 16:50:01.511801-0400 PIT[20770:919422] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

2017-08-23 16:50:01.511934-0400 PIT[20770:919422] Task <2F2B33A6-0ADD-4676-B859-E602DCA2BDB6>.<0> HTTP load failed (error code: -1200 [3:-9802])

2017-08-23 16:50:01.512112-0400 PIT[20770:919424] NSURLConnection finished with error - code -1200

Does it happen in the project you download and run by following the instructions from here: ?https://backendless.com/docs/ios/doc.html#quick_start_guide

Yes, that worked. I even tried shifting and tweaking things to be more like the way I have it and it still worked every time.

Very strange