Skip to content

Commit

Permalink
Support service callbacks with 1 or 2 arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaurw01 committed Aug 20, 2015
1 parent 92c55f1 commit 91a8f7a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/DfpUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,30 @@ DfpUser.prototype.getService = function (service, callback, version) {
}
};

// If the callback accepts two arguments, make note that we should pass errors
// to the callback.
//
var callbackSupportsError = callback.length === 2;

this.getTokens(function (err, tokens) {

if (err) {
console.log('getTokens Error ' + err);
return callback(new Error('getTokens Error'));
var error = new Error('getTokens Error');
if (callbackSupportsError) {
return callback(error);
}
throw error;
}

soap.createClient(soap_wsdl, options, function (err, client) {
if (err) {
console.log('Create Client Error ' + err);
return callback(new Error('Unable to get token'));
var error = new Error('Unable to get token');
if (callbackSupportsError) {
return callback(error);
}
throw error;
}

client.addSoapHeader(dfpUser.getSOAPHeader(), '', '', '');
Expand All @@ -88,8 +101,10 @@ DfpUser.prototype.getService = function (service, callback, version) {
}
}

return callback(null, serviceInstance);

if (callbackSupportsError) {
return callback(null, serviceInstance);
}
callback(serviceInstance);
});
});

Expand Down

0 comments on commit 91a8f7a

Please sign in to comment.