courier
courier copied to clipboard
Better Error Handling
Hi,
After changing the handheld device, I noticed that the library stopped working. The Android Wear device stopped receiving messages, and there was no error messages on the logcat at all. After spending some hour debugging the library I noticed that almost all objects related to the result of a request or connection were not used at all. I had to download the library and put Logs in between the code to understand exactly where the request was getting lost.
In the end, the problem was with the GoogleApiClient, it was not being returned and because of that, I was not receiving any requests on the android wear device.
More specifically this piece of code:
final ConnectionResult result = googleApiClient.blockingConnect();
if(!result.isSuccess()) {
googleApiClient = null;
}
The ConnectionResult status is ignored and there is no way for the developer to know why the connection failed. The problem in my case was that the Google Play Services library was not up to date.
My suggestion here is to log the reason why the ConnectionResult was not successful. Not only for this piece of code, but also for the requests.
I will definitely take this on board as an issue and try to make this kind of thing easier.
Logging would be helpful, though I also want to avoid polluting the logs when it can't connect to the API, which can occur if the user simply doesn't have a watch.
I'm thinking that we could get the best of both worlds by using an "error mode" that can be set to help troubleshooting. This mode could be set to SILENT, LOG, or CRASH. Crashing could be helpful as it would be immediately apparent to the developer that something went wrong and they wouldn't have to hunt through the logcat for the reason.
There is currently a method Courier.isWearableApiAvailable
that just returns whether or not we can connect to the API. I'm thinking that it could also be helpful to return the error code here, so that the app can properly prompt the user for resolvable errors such as needing to update Google Play Services.
I think both ways are great to help devs find these small issues. :-)