Skip to content

Commit

Permalink
gracefully detect and handle when user declines authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
sstrigler committed Jun 25, 2012
1 parent 9f2c438 commit 46ca603
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/modules/tumblr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var oauthModule = require('./oauth')
, Parser = require('xml2js').Parser;
, Parser = require('xml2js').Parser
, url = require('url');

var twitter = module.exports =
var tumblr = module.exports =
oauthModule.submodule('tumblr')
.apiHost('http://www.tumblr.com/api')
.oauthHost('http://www.tumblr.com')
Expand All @@ -21,6 +22,20 @@ oauthModule.submodule('tumblr')
});
return promise;
})
.authCallbackDidErr( function (req) {
var parsedUrl = url.parse(req.url, true);
return !parsedUrl.query || !parsedUrl.query.oauth_token;
})
.handleAuthCallbackError( function (req, res) {
if (res.render) {
res.render(__dirname + '/../views/auth-fail.jade', {
errorDescription: 'The user denied your request'
});
} else {
// TODO Replace this with a nice fallback
throw new Error("You must configure handleAuthCallbackError if you are not using express");
}
})
.convertErr( function (data) {
return data.data;
});
return new Error(data.data);
});

0 comments on commit 46ca603

Please sign in to comment.