Skip to content

Commit

Permalink
Fixed issue desmondmorris#23 - Better callback patterns
Browse files Browse the repository at this point in the history
Node standard is callback(err, data), and this patch updates the code to reflect this.
  • Loading branch information
sedge committed Aug 23, 2014
1 parent 10ec388 commit bdc6a31
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Twitter.prototype.get = function(url, params, callback) {
} else {
try {
var json = JSON.parse(data);
callback(json);
callback(null, json);
} catch(err) {
callback(err);
}
Expand Down Expand Up @@ -155,7 +155,7 @@ Twitter.prototype.post = function(url, content, content_type, callback) {
} else {
try {
var json = JSON.parse(data);
callback(json);
callback(null, json);
} catch(err) {
callback(err);
}
Expand Down Expand Up @@ -308,7 +308,7 @@ Twitter.prototype.stream = function(method, params, callback) {
});
request.end();

if ( typeof callback === 'function' ) callback(stream);
if ( typeof callback === 'function' ) callback(null, stream);
return this;
};

Expand Down Expand Up @@ -624,7 +624,10 @@ Twitter.prototype.userProfileImage = function(id, params, callback) {
this.options.access_token_secret);
request.on('response', function(response) {
// return the location or an HTTP error
callback(response.headers.location || new Error('HTTP Error ' +
if (response.headers.location) {
return callback(response.headers.location);
}
callback(new Error('HTTP Error ' +
response.statusCode + ': ' +
http.STATUS_CODES[response.statusCode]));
});
Expand Down Expand Up @@ -682,7 +685,7 @@ Twitter.prototype.getLists = function(id, params, callback) {
defaults.user_id = id;

params = merge(defaults, params);
console.log(params);

var url = '/lists.json';
this._getUsingCursor(url, params, callback);
return this;
Expand Down Expand Up @@ -1264,7 +1267,7 @@ Twitter.prototype._getUsingCursor = function(url, params, callback) {
if (data[key]) result = result.concat(data[key]);

if (data.next_cursor_str === '0') {
callback(result);
callback(null, result);
} else {
params.cursor = data.next_cursor_str;
self.get(url, params, fetch);
Expand Down

0 comments on commit bdc6a31

Please sign in to comment.