Permalink
Browse files

Wrap error for informative messages.

  • Loading branch information...
1 parent 34d0de7 commit 06f407480b1760f06a2762e8a9d1abf61d02cb38 @jaredhanson committed Jan 24, 2013
Showing with 6 additions and 2 deletions.
  1. +3 −2 lib/passport-37signals/strategy.js
  2. +3 −0 test/strategy-test.js
@@ -2,7 +2,8 @@
* Module dependencies.
*/
var util = require('util')
- , OAuth2Strategy = require('passport-oauth').OAuth2Strategy;
+ , OAuth2Strategy = require('passport-oauth').OAuth2Strategy
+ , InternalOAuthError = require('passport-oauth').InternalOAuthError;
/**
@@ -71,7 +72,7 @@ util.inherits(Strategy, OAuth2Strategy);
*/
Strategy.prototype.userProfile = function(accessToken, done) {
this._oauth2.get('https://launchpad.37signals.com/authorization.json', accessToken, 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);
@@ -101,6 +101,9 @@ vows.describe('Thirty7SignalsStrategy').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);
},

0 comments on commit 06f4074

Please sign in to comment.