Skip to content

Commit

Permalink
Wrap json parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Apr 16, 2017
1 parent f959608 commit 4bbbb8d
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/Adapters/Auth/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion src/Adapters/Auth/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion src/Adapters/Auth/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 7 additions & 2 deletions src/Adapters/Auth/janrainengage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand All @@ -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);
});
});

Expand Down
6 changes: 5 additions & 1 deletion src/Adapters/Auth/linkedin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion src/Adapters/Auth/meetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion src/Adapters/Auth/qq.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
6 changes: 5 additions & 1 deletion src/Adapters/Auth/spotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion src/Adapters/Auth/vkontakte.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
6 changes: 5 additions & 1 deletion src/Adapters/Auth/wechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
6 changes: 5 additions & 1 deletion src/Adapters/Auth/weibo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 4bbbb8d

Please sign in to comment.