Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: criso/fbgraph
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: Sirach99/fbgraph
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Apr 30, 2024

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    768fafb View commit details

Commits on Jul 28, 2024

  1. Merge pull request #1 from Sirach99/double-callback-fix

    Fix error handling in get and post methods
    Sirach99 authored Jul 28, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5f05a6b View commit details
Showing with 42 additions and 22 deletions.
  1. +42 −22 lib/graph.js
64 changes: 42 additions & 22 deletions lib/graph.js
Original file line number Diff line number Diff line change
@@ -177,14 +177,16 @@ Graph.prototype.end = function (body) {

Graph.prototype.get = function () {
var self = this;
let callbackCalled = false;

return request.get(this.options, function(err, res, body) {
return request.get(this.options, (err, res, body) => {
if (err) {
self.callback({
message: 'Error processing https request'
, exception: err
}, null);

handleRequestError(
self,
callbackCalled,
{ message: 'Error processing https request in get', exception: err },
);
callbackCalled = true;
return;
}

@@ -196,11 +198,13 @@ Graph.prototype.get = function () {
}

self.end(body);
}).on('error', function(err) {
self.callback({
message: 'Error processing https request'
, exception: err
}, null);
}).on('error', (err) => {
handleRequestError(
self,
callbackCalled,
{ message: 'Error processing https request in get', exception: err },
);
callbackCalled = true;
});
};

@@ -215,28 +219,44 @@ Graph.prototype.post = function() {
, postData = qs.stringify(this.postData);

this.options.body = postData;
let callbackCalled = false;

return request(this.options, function (err, res, body) {
return request(this.options, (err, res, body) => {
if (err) {
self.callback({
message: 'Error processing https request'
, exception: err
}, null);

handleRequestError(
self,
callbackCalled,
{ message: 'Error processing https request in post', exception: err },
);
callbackCalled = true;
return;
}

self.end(body);
})
.on('error', function(err) {
self.callback({
message: 'Error processing https request'
, exception: err
}, null);
.on('error', (err) => {
handleRequestError(
self,
callbackCalled,
{ message: 'Error processing https request in post', exception: err },
);
callbackCalled = true;
});

};

/**
* Handles request errors
* @param {object} self - the graph object
* @param {boolean} callbackCalled - whether the callback has been called
* @param {object} error - the error object
*/
function handleRequestError(self, callbackCalled, error) {
if (!callbackCalled) {
self.callback(error);
}
}

/**
* Accepts an url an returns facebook
* json data to the callback provided