Skip to content

Commit

Permalink
add url to error objects
Browse files Browse the repository at this point in the history
  • Loading branch information
polotek committed Feb 23, 2011
1 parent bd180c6 commit 75a4067
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
26 changes: 14 additions & 12 deletions lib/evented-twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,6 @@ function apiCall(urlPath, method, format, params, opts, cb) {
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, res);
}

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

var authObject
Expand All @@ -300,7 +289,20 @@ function apiCall(urlPath, method, format, params, opts, cb) {
client = ra.createRequestAdapter();
}

this._lastAPICall = 'http://' + REST_API_HOST + REST_API_ENDPOINT + urlPath;
var lastAPICall = this._lastAPICall = 'http://' + REST_API_HOST + REST_API_ENDPOINT + urlPath;

function responseHandler(err, data, res) {
if(err) {
err.et = { url: lastAPICall };
return errHandler(err, data);
}

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

cb(null, data, res);
}

if(method == 'POST') {
client.post({ uri: this._lastAPICall
Expand Down
11 changes: 10 additions & 1 deletion test/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,13 @@ function testDM() {
});
}

batch([ testTimeline, testUser, testTweet, testAccount, testDM ], { batchSize: 1 });
function testMisc() {
t.showUser('json', null, function(err, data, res) {
assert.ok(err);
var url = 'http://api.twitter.com/1/users/show.json';
assert.equal(url, err.et.url, 'Errors should contain the url that was requested');
//handler('showUser')(err, data, res);
});
}

batch([ testTimeline, testUser, testTweet, testAccount, testDM, testMisc ], { batchSize: 1 });

0 comments on commit 75a4067

Please sign in to comment.