Skip to content

Commit

Permalink
better error handling, surface twitter error on statusCode !== 200
Browse files Browse the repository at this point in the history
  • Loading branch information
polotek committed Jan 29, 2011
1 parent 526578e commit b698986
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/evented-twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,26 @@ function apiCall(urlPath, method, format, params, authRequired, errHandler, cb)
}
}

function responseHandler(err, data) {
if(err) {
if(typeof errHandler === 'function')
return errHandler(err, data);
else
return cb(err);
if(typeof errHandler != 'function')
errHandler = cb;

function responseHandler(err, data, res) {
if(err)
return errHandler(err, data);

if(res && res.statusCode && res.statusCode !== 200) {
return errHandler(new Error('Twitter error (' + res.statusCode + ')'), data);
}
cb(null, data);

cb(null, data, res);
}

var headers = { "User-Agent": "evented-twitter - node.js" };

var authObject
, client;
if(authRequired && params && params.auth) {
if(_.isString(params.auth) && authHandlers[params.auth]) {
if(authHandlers[params.auth]) {
authObject = authHandlers[params.auth];
authObject = authObject.authenticate(params);
} else if(params.auth.authenticate) {
Expand Down Expand Up @@ -257,8 +261,8 @@ TwitterBase.prototype = {
, set password(value) { this._password = value; }
, get FORMATS() { return this._FORMATS; }
, get lastAPICall() { return this._lastAPICall; }
, 'authHandler': authHandlers.basic
, 'apiCall': apiCall
, authHandler: authHandlers.basic
, apiCall: apiCall
};

function Twitter(){
Expand Down

0 comments on commit b698986

Please sign in to comment.