jInstagram icon indicating copy to clipboard operation
jInstagram copied to clipboard

`LogHelper` fails to pretty-print received JSON response from Instagram

Open arinto opened this issue 8 years ago • 5 comments

I encountered this intermittent error on version 1.1.4. The org.jinstagram.utils.LogHelper fails to pretty-print the received JSON from Instagram. Check the stack trace below. Could we simply follow the suggestion (ie. Use JsonReader.setLenient(true) ) ?

Unfortunately I didn't log/capture the actual response from Instagram, so at this point, I'm not sure what kind of response that Instagram sends to us.

10:26:54.943 [pool-1-thread-1] ERROR o.l.p.r.CheckMediaProfileRunnable - A wild throwable appears! idToCrawl: 53267135
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 6
        at com.google.gson.JsonParser.parse(JsonParser.java:65) ~[insta-crawler-3.0.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at com.google.gson.JsonParser.parse(JsonParser.java:45) ~[insta-crawler-3.0.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at org.jinstagram.utils.LogHelper.prettyPrintJSONResponse(LogHelper.java:98) ~[insta-crawler-3.0.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at org.jinstagram.Instagram.createInstagramObject(Instagram.java:928) ~[insta-crawler-3.0.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at org.jinstagram.Instagram.getRecentMediaFeed(Instagram.java:256) ~[insta-crawler-3.0.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at org.larc.palanteer.runnable.CheckMediaProfileRunnable.getMediaWithinAMonth(CheckMediaProfileRunnable.java:301) ~[insta-crawler-3.0.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at org.larc.palanteer.runnable.CheckMediaProfileRunnable.run(CheckMediaProfileRunnable.java:170) ~[insta-crawler-3.0.0-SNAPSHOT-jar-with-dependencies.jar:na]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_51]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_51]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_51]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_51]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_51]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_51]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_51]

arinto avatar Dec 22 '15 02:12 arinto

@arinto Can you try using the JsonReader.setLenient(true) ?

If it still doesn't work, I think we need to catch the MalformedJsonException in the LogHelper class.

sachin-handiekar avatar Dec 22 '15 09:12 sachin-handiekar

Hang on, I'll let you know once I try.

arinto avatar Dec 28 '15 02:12 arinto

Same here. Where are we suppose to setLenient(true)? Is there anyway to use an instance of jInstagram to configure the JSON reader?

jvence avatar Jan 18 '16 10:01 jvence

@sachin-handiekar this probably happens when the Instagram API doesn't return 200 OK. For example, try TagMedia.getRecent with an invalid tag, e.g.: "@test". The response code will be 404, and the response document will be HTML instead of JSON.

To prevent this bug, we should be checking for 200 OK, and otherwise return an error / throw an instagram exception.

YousefED avatar May 12 '16 13:05 YousefED

Thanks @YousefED . Will have a look at the code and add a condition to check for 200 OK status code.

sachin-handiekar avatar May 14 '16 07:05 sachin-handiekar