Closed JPellegrino closed 8 years ago
Может, сервер отбил вместо ответа страницу с ошибкой. Что вызывали, как получился такой ответ?
Sorry, I can't read cyrillic but I guess you want some details. I am using two APIs : 'newsfeed.search' and 'users.get'. I first call 'newsfeed.search' throught:
client.request('newsfeed.search', query, function (data) {
callback(data);
});
with query:
var query = {
'q': 'example',
'extended': 1,
'count': 200,
'version': 5.34
}
Then for all the results, I call 'users.get' throught:
client.request('users.get', user_query, function (data) {
if (data.error) {
return callback(null);
}
var user = data.response[0];
callback(user);
});
with query:
var user_query = {
'user_ids': user_id,
'fields': user_fields,
'version': 5.34
};
Where the user_id obtained with the previous call and:
var user_fields = [
"uid",
"sex",
"bdate",
"city",
"country",
"counters",
"photo_50",
"timezone",
]
I don't know from which of the two types of call the error is coming but it completely crashes my app, although the error seems to be really rare...
Oh, sorry, I thought you Russian speaker (most of SDK users are Russian speakers). Thank you, you was right — I asked you about details.
Sometimes vk.com can send HTML page with error text. And try to run code like this
client.request('users.get', user_query, function (data) {
console.log(data);
});
and check the output.
Thanks for your quick responses but I though, by ready the error message that the crash occurs at in sdk.js line 288 column 26 where I can read:
var o = JSON.parse(apiResponse);
So my question now is: is the sdk.js script handling properly the possibility of html answer ?
Obviously no, but should do that. I think I can fix it on the week or you can do it by yourself and I'll merge it.
Thank you!
Ok I'll try to propose you a fix as fast as possible, but if someone skilled guy is listening around it could be nice to have idea to handle this properly...
Thank you for pull request.
I've made several changes and now SDK emits parse-error
event in this case
vk.on('parse-error', function(_e) {
console.log(_e);
});
NPM package has been updated. Feel free too download new version. Thank you!