Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

LogHelper fails to pretty-print received JSON response from Instagram #140

Open
arinto opened this issue Dec 22, 2015 · 5 comments
Open

Comments

@arinto
Copy link
Contributor

arinto commented Dec 22, 2015

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]

@sachin-handiekar
Copy link
Owner

@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.

@arinto
Copy link
Contributor Author

arinto commented Dec 28, 2015

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

@jvence
Copy link

jvence commented Jan 18, 2016

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

@YousefED
Copy link
Contributor

@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.

@sachin-handiekar
Copy link
Owner

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants