Skip to content

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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Connectors/Facebook/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,19 @@ 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) {}
}
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);
Expand Down