Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SyntaxError: Unexpected end of input] while trying to get IG posts #104

Open
jatinseth2007 opened this issue Oct 3, 2016 · 6 comments
Open

Comments

@jatinseth2007
Copy link

jatinseth2007 commented Oct 3, 2016

Hello,

I am trying to fetch IG posts of the users by using the method

var def = Q.defer();

ig.user_media_recent(user_id.toString(), {
count: 10000
},
function (err, medias, pagination, remaining, limit) {
if (!err) {
def.resolve(medias, pagination);
} else {
def.reject(_common_worker.generate_worker_error(err, {
error_type: 'IG',
ig_id: user_id,
message: "Error in fetching data from Instagram api get_user_post_timestamp method"
}, __filename));
}
});
return def.promise;

But for some users the control always go in ELSE part with error shown below:

[SyntaxError: Unexpected end of input]

@jatinseth2007
Copy link
Author

jatinseth2007 commented Oct 3, 2016

I have done some digging in error, i have found that i am getting right data from Instagram but I am getting incomplete JSON object in "pagination" var in else method: I am getting the response ended like ", "profile_picture": "https://scontent.cdninstagram.com/t5"

@jspavlick
Copy link
Contributor

+1 - I am starting to see this.

@jspavlick
Copy link
Contributor

jspavlick commented Oct 12, 2016

I'm seeing this where in call, req.on('end' is firing before the actual end. body.length < parseInt(res.headers['content-length'], 10) and I get a JSON parsing error. If I prevent the JSON parsing under this condition, I am shortly thereafter greeted with ECONNRESET.

@the-yadu
Copy link

Can we redo the call in case of end firing early?

@jatinseth2007
Copy link
Author

Okay, so what could be the solution for this case ? what could we do to prevent it ?

@jspavlick
Copy link
Contributor

Adding some sort of if statement check like I previously suggested, could prevent the JSON.parse error, and instead hit the ECONNRESET. Then, in your application code, you can handle the error similarly as you would any 500 error. My limited understanding is that ECONNRESET is caused by the other end (Instagram, in this case) closing the socket unexpectedly. Personally, I'd consider that along the lines of a 500. -shrugs-

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

No branches or pull requests

3 participants