Skip to content

Commit

Permalink
Merge pull request #15 from Subomi/master
Browse files Browse the repository at this point in the history
bug fix & upgrade in request call
  • Loading branch information
subomi committed Jan 5, 2017
2 parents aeab4f6 + 0ce2aeb commit 303410f
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions index.js
Expand Up @@ -81,7 +81,6 @@ Paystack.prototype = {
// Get arguments in endpoint e.g {id} in customer/{id} and pull
// out from array
var argsInEndpoint = endpoint.match(/{[^}]+}/g);

if (argsInEndpoint) {
l = argsInEndpoint.length;
// Do we have one or more?
Expand Down Expand Up @@ -141,19 +140,21 @@ Paystack.prototype = {
if (qs)
options.qs = qs;

request(options, function(error, response, body) {

// return body
if (callback){

// Error from API??
if (!body.status) {
error = body;
body = null;
}

return callback(error, body);
}
request(options, function(error, response, body) {
// request module error as not been previously handled properly.
// To see this error try running this module without internet connection
if(!error) {
if(callback){
if(response.statusCode > 201) {
error = body;
body = null;
}

return callback(error, body);
}
// gc would throw response away
}
throw new Error(error);
});

}
Expand Down

0 comments on commit 303410f

Please sign in to comment.