From 3901b76f7ff09d3312720a87b3fa705171ae1c9c Mon Sep 17 00:00:00 2001 From: Jared Hanson Date: Sat, 28 Apr 2012 09:49:34 -0700 Subject: [PATCH] Wrap error for informative messages. --- lib/passport-tumblr/strategy.js | 5 +++-- test/strategy-test.js | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/passport-tumblr/strategy.js b/lib/passport-tumblr/strategy.js index a94d119..19afc48 100644 --- a/lib/passport-tumblr/strategy.js +++ b/lib/passport-tumblr/strategy.js @@ -2,7 +2,8 @@ * Module dependencies. */ var util = require('util') - , OAuthStrategy = require('passport-oauth').OAuthStrategy; + , OAuthStrategy = require('passport-oauth').OAuthStrategy + , InternalOAuthError = require('passport-oauth').InternalOAuthError; /** @@ -70,7 +71,7 @@ util.inherits(Strategy, OAuthStrategy); */ Strategy.prototype.userProfile = function(token, tokenSecret, params, done) { this._oauth.get('http://api.tumblr.com/v2/user/info', token, tokenSecret, function (err, body, res) { - if (err) { return done(err); } + if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); } try { var json = JSON.parse(body); diff --git a/test/strategy-test.js b/test/strategy-test.js index 4c57869..b3c423c 100644 --- a/test/strategy-test.js +++ b/test/strategy-test.js @@ -124,6 +124,9 @@ vows.describe('TumblrStrategy').addBatch({ 'should error' : function(err, req) { assert.isNotNull(err); }, + 'should wrap error in InternalOAuthError' : function(err, req) { + assert.equal(err.constructor.name, 'InternalOAuthError'); + }, 'should not load profile' : function(err, profile) { assert.isUndefined(profile); },