Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Return an error if FB returns error in the result
Browse files Browse the repository at this point in the history
  • Loading branch information
ouadie-lahdioui committed Mar 22, 2018
1 parent 2a96d75 commit 97b3c1c
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions lib/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,23 @@ function Facebookbot(configuration) {
facebook_botkit.log('Could not configure messenger profile');
reject(err);
} else {
facebook_botkit.debug('Successfully configured messenger profile', message);
resolve(message);
var results = null;
try {
results = JSON.parse(body);
} catch (err) {
facebook_botkit.log('ERROR in messenger profile API call: Could not parse JSON', err, body);
reject(err);
}

if (results) {
if (results.error) {
facebook_botkit.log('ERROR in messenger profile API call: ', results.error.message);
reject(results.error);
} else {
facebook_botkit.debug('Successfully configured messenger profile ', body);
resolve(message);
}
}
}
});
});
Expand All @@ -715,16 +730,29 @@ function Facebookbot(configuration) {
function(err, res, body) {
if (err) {
facebook_botkit.log('Could not get messenger profile');
if (cb) {
cb(err);
}
reject(err);
if (cb) cb(err)
else reject(err)
} else {
facebook_botkit.debug('Successfully got messenger profile ', body);
if (cb) {
cb(null, body);
var results = null;
try {
results = JSON.parse(body);
} catch (err) {
facebook_botkit.log('ERROR in messenger profile API call: Could not parse JSON', err, body);
if (cb) cb(err)
else reject(err)
}

if (results) {
if (results.error) {
facebook_botkit.log('ERROR in messenger profile API call: ', results.error.message);
if (cb) cb(results.error)
else reject(results.error)
} else {
facebook_botkit.debug('Successfully got messenger profile ', body);
if (cb) cb(null, body)
else resolve(body)
}
}
resolve(body);
}
});
});
Expand Down

0 comments on commit 97b3c1c

Please sign in to comment.