Permalink
Browse files

Wrap error for informative messages.

  • Loading branch information...
1 parent fe3eb13 commit 7276e2a4cb0d45334ec33ee0bf09e316639b4aa3 @jaredhanson committed Apr 28, 2012
Showing with 6 additions and 2 deletions.
  1. +3 −2 lib/passport-github/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;
/**
@@ -76,7 +77,7 @@ util.inherits(Strategy, OAuth2Strategy);
*/
Strategy.prototype.userProfile = function(accessToken, done) {
this._oauth2.get('https://api.github.com/user', 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);
View
@@ -102,6 +102,9 @@ vows.describe('GitHubStrategy').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 7276e2a

Please sign in to comment.