Skip to content
Browse files

Wrap error for informative messages.

  • Loading branch information...
1 parent f55117b commit 8ad79d81ca576ef3db936ec439ad432e35f1b866 @jaredhanson jaredhanson committed Apr 27, 2012
Showing with 12 additions and 4 deletions.
  1. +3 −2 lib/passport-google-oauth/oauth.js
  2. +3 −2 lib/passport-google-oauth/oauth2.js
  3. +3 −0 test/oauth-test.js
  4. +3 −0 test/oauth2-test.js
View
5 lib/passport-google-oauth/oauth.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;
/**
@@ -71,7 +72,7 @@ util.inherits(Strategy, OAuthStrategy);
*/
Strategy.prototype.userProfile = function(token, tokenSecret, params, done) {
this._oauth.get('https://www.google.com/m8/feeds/contacts/default/full?max-results=1&alt=json', 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);
View
5 lib/passport-google-oauth/oauth2.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;
/**
@@ -70,7 +71,7 @@ util.inherits(Strategy, OAuth2Strategy);
*/
Strategy.prototype.userProfile = function(accessToken, done) {
this._oauth2.get('https://www.googleapis.com/oauth2/v1/userinfo', 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
3 test/oauth-test.js
@@ -118,6 +118,9 @@ vows.describe('GoogleStrategy').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);
},
View
3 test/oauth2-test.js
@@ -139,6 +139,9 @@ vows.describe('GoogleStrategy').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 8ad79d8

Please sign in to comment.
Something went wrong with that request. Please try again.