Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Corrected possible chance of infinite error loop in GetProfile. #956

Open
wants to merge 1 commit into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 3 deletions.
  1. +6 −3 Connectors/Facebook/lib.js
View
9 Connectors/Facebook/lib.js
@@ -122,6 +122,8 @@ var profile;
exports.getProfile = function(cbDone) {
if(!profile) {
try {
+ //Problem: if an error occurred, the profile.json will have error message,
+ //the correct profile will not be retrieved and a cycle of error is created.
profile = JSON.parse(fs.readFileSync('profile.json'));
return cbDone(null, profile);
} catch (err) {}
@@ -129,9 +131,10 @@ exports.getProfile = function(cbDone) {
if(!profile) {
request.get({uri:'https://graph.facebook.com/me?access_token=' + auth.accessToken + '&fields='+allUserFields, json:true},
function(err, resp, profile) {
- fs.writeFile('profile.json', JSON.stringify(profile), function(err) {
- cbDone(err, profile);
- });
+ if(profile.id) //Solution: if an error occurred, the profile.json will not be created.
+ fs.writeFile('profile.json', JSON.stringify(profile), function(err) {
+ cbDone(err, profile);
+ });
});
} else {
cbDone(null, profile);
Something went wrong with that request. Please try again.