I was playing with the api and started receiving fatal errors trying to fetch programs:
Exception in thread "main" org.schedulesdirect.api.exception.InvalidJsonObjectException: Program[EP012359090001]: Program[SH012359090000]: JSONObject["titles"] not found.
at org.schedulesdirect.api.Program.<init>(Program.java:687)
at org.schedulesdirect.api.NetworkEpgClient.fetchPrograms(NetworkEpgClient.java:519)
at org.schedulesdirect.api.NetworkEpgClient.prefetch(NetworkEpgClient.java:437)
at org.schedulesdirect.api.NetworkEpgClient.fetchSchedules(NetworkEpgClient.java:472)
at org.schedulesdirect.api.Lineup.fetchDetails(Lineup.java:136)
at net.cracauer.jna.TestSDJson.main(TestSDJson.java:21)
Caused by: org.schedulesdirect.api.exception.InvalidJsonObjectException: Program[SH012359090000]: JSONObject["titles"] not found.
at org.schedulesdirect.api.Program.<init>(Program.java:687)
at org.schedulesdirect.api.NetworkEpgClient.fetchPrograms(NetworkEpgClient.java:519)
at org.schedulesdirect.api.NetworkEpgClient.fetchProgram(NetworkEpgClient.java:426)
at org.schedulesdirect.api.Program.<init>(Program.java:685)
... 5 more
Caused by: org.json.JSONException: JSONObject["titles"] not found.
at org.json.JSONObject.get(JSONObject.java:473)
at org.json.JSONObject.getJSONObject(JSONObject.java:573)
at org.schedulesdirect.api.Program.<init>(Program.java:526)
... 8 more</init></init></init></init>
The json that was received was:
{"datetime":"2014-10-03T02:19:34Z","code":6000,"response":"INVALID_PROGRAMID","message":"Could not find requested programID.","serverID":"AWS-SD-web.1","programID":"SH012359090000"}
It seems like this could be handled more gracefully - perhaps just ignored. Happy to provide a patch if you want.
I will always happily accept patches. :)
So the issue here is NetworkEpgClient.fetchPrograms() doesn't handle the invalid id response. It should recognize the error response and set the Program to null for the id instead of throwing an exception. This would make the behaviour equal to that of ZipEpgClient when fetching a non-existent id.
This bug also makes the NetworkEpgClient nearly useless for fetching program objects since all Programs try to attach the seriesInfo obj to themselves and many ids won't have a series info obj, causing the exception.
Most apps build program objs from local cache, which is why my production apps haven't hit this, but it definitely needs to be addressed asap. Unfortunately, I'm out of town for another couple weeks still so won't be able to release a fix until I return home.
Fixed in api 20140530