diff --git a/src/Adapters/Auth/facebook.js b/src/Adapters/Auth/facebook.js index 84f8956678..ab846e43e6 100644 --- a/src/Adapters/Auth/facebook.js +++ b/src/Adapters/Auth/facebook.js @@ -43,7 +43,11 @@ function graphRequest(path) { data += chunk; }); res.on('end', function() { - data = JSON.parse(data); + try { + data = JSON.parse(data); + } catch(e) { + return reject(e); + } resolve(data); }); }).on('error', function() { diff --git a/src/Adapters/Auth/github.js b/src/Adapters/Auth/github.js index e6e2c05e8c..146fbdc6f2 100644 --- a/src/Adapters/Auth/github.js +++ b/src/Adapters/Auth/github.js @@ -36,7 +36,11 @@ function request(path, access_token) { data += chunk; }); res.on('end', function() { - data = JSON.parse(data); + try { + data = JSON.parse(data); + } catch(e) { + return reject(e); + } resolve(data); }); }).on('error', function() { diff --git a/src/Adapters/Auth/google.js b/src/Adapters/Auth/google.js index 4699c83789..7cc414922a 100644 --- a/src/Adapters/Auth/google.js +++ b/src/Adapters/Auth/google.js @@ -55,7 +55,11 @@ function request(path) { data += chunk; }); res.on('end', function() { - data = JSON.parse(data); + try { + data = JSON.parse(data); + } catch(e) { + return reject(e); + } resolve(data); }); }).on('error', function() { diff --git a/src/Adapters/Auth/janrainengage.js b/src/Adapters/Auth/janrainengage.js index 4df5701a41..7de682e7d4 100644 --- a/src/Adapters/Auth/janrainengage.js +++ b/src/Adapters/Auth/janrainengage.js @@ -41,7 +41,7 @@ function request(api_key, auth_token) { } }; - return new Promise(function (resolve) { + return new Promise(function (resolve, reject) { // Create the post request. var post_req = https.request(post_options, function (res) { var data = ''; @@ -52,7 +52,12 @@ function request(api_key, auth_token) { }); // Once we have all the data, we can parse it and return the data we want. res.on('end', function () { - resolve(JSON.parse(data)); + try { + data = JSON.parse(data); + } catch(e) { + return reject(e); + } + resolve(data); }); }); diff --git a/src/Adapters/Auth/linkedin.js b/src/Adapters/Auth/linkedin.js index 63c6cd97e1..de5fc66ce5 100644 --- a/src/Adapters/Auth/linkedin.js +++ b/src/Adapters/Auth/linkedin.js @@ -42,7 +42,11 @@ function request(path, access_token, is_mobile_sdk) { data += chunk; }); res.on('end', function() { - data = JSON.parse(data); + try { + data = JSON.parse(data); + } catch(e) { + return reject(e); + } resolve(data); }); }).on('error', function() { diff --git a/src/Adapters/Auth/meetup.js b/src/Adapters/Auth/meetup.js index e5c7e2c91e..bb14dc547b 100644 --- a/src/Adapters/Auth/meetup.js +++ b/src/Adapters/Auth/meetup.js @@ -35,7 +35,11 @@ function request(path, access_token) { data += chunk; }); res.on('end', function() { - data = JSON.parse(data); + try { + data = JSON.parse(data); + } catch(e) { + return reject(e); + } resolve(data); }); }).on('error', function() { diff --git a/src/Adapters/Auth/qq.js b/src/Adapters/Auth/qq.js index 376a5e650b..6f4dfdc0cf 100644 --- a/src/Adapters/Auth/qq.js +++ b/src/Adapters/Auth/qq.js @@ -32,7 +32,11 @@ function graphRequest(path) { throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'qq auth is invalid for this user.'); } data = data.substring(starPos + 1,endPos - 1); - data = JSON.parse(data); + try { + data = JSON.parse(data); + } catch(e) { + return reject(e); + } resolve(data); }); }).on('error', function () { diff --git a/src/Adapters/Auth/spotify.js b/src/Adapters/Auth/spotify.js index 7c39ed65e9..701422c585 100644 --- a/src/Adapters/Auth/spotify.js +++ b/src/Adapters/Auth/spotify.js @@ -49,7 +49,11 @@ function request(path, access_token) { data += chunk; }); res.on('end', function() { - data = JSON.parse(data); + try { + data = JSON.parse(data); + } catch(e) { + return reject(e); + } resolve(data); }); }).on('error', function() { diff --git a/src/Adapters/Auth/vkontakte.js b/src/Adapters/Auth/vkontakte.js index 0fdf28f2f1..4e57b25993 100644 --- a/src/Adapters/Auth/vkontakte.js +++ b/src/Adapters/Auth/vkontakte.js @@ -47,7 +47,11 @@ function request(host, path) { data += chunk; }); res.on('end', function () { - data = JSON.parse(data); + try { + data = JSON.parse(data); + } catch(e) { + return reject(e); + } resolve(data); }); }).on('error', function () { diff --git a/src/Adapters/Auth/wechat.js b/src/Adapters/Auth/wechat.js index 77cd7cfa2a..9432b7c5c3 100644 --- a/src/Adapters/Auth/wechat.js +++ b/src/Adapters/Auth/wechat.js @@ -26,7 +26,11 @@ function graphRequest(path) { data += chunk; }); res.on('end', function () { - data = JSON.parse(data); + try { + data = JSON.parse(data); + } catch(e) { + return reject(e); + } resolve(data); }); }).on('error', function () { diff --git a/src/Adapters/Auth/weibo.js b/src/Adapters/Auth/weibo.js index 8daf11de43..64efada2f6 100644 --- a/src/Adapters/Auth/weibo.js +++ b/src/Adapters/Auth/weibo.js @@ -39,7 +39,11 @@ function graphRequest(access_token) { data += chunk; }); res.on('end', function () { - data = JSON.parse(data); + try { + data = JSON.parse(data); + } catch(e) { + return reject(e); + } resolve(data); }); res.on('error', function () {