<commit_before>var oauthModule = require('./oauth')
  , Parser = require('xml2js').Parser;

var twitter = module.exports =
oauthModule.submodule('tumblr')
  .apiHost('http://www.tumblr.com/api')
  .oauthHost('http://www.tumblr.com')
  .entryPath('/auth/tumblr')
  .callbackPath('/auth/tumblr/callback')
  .sendCallbackWithAuthorize(false)
  .fetchOAuthUser( function (accessToken, accessTokenSecret, params) {
    var promise = this.Promise();
    this.oauth.get(this.apiHost() + '/authenticate', accessToken, accessTokenSecret, function (err, data) {
      if (err) return promise.fail(err);
      var parser = new Parser();
      parser.on('end', function (result) {
        var oauthUser;
        if(result.tumblelog instanceof Array){
          oauthUser = result.tumblelog[0]['@'];
        } else {
          oauthUser = result.tumblelog['@'];
        }
        promise.fulfill(oauthUser);
      });
      parser.parseString(data);
    });
    return promise;
  })
  .convertErr( function (data) {
    return data.data;
  });<commit_msg>fix uncatched error when declining tumblr auth<commit_after>var oauthModule = require('./oauth')
, Parser = require('xml2js').Parser
, url = require('url');

var tumblr = module.exports =
oauthModule.submodule('tumblr')
  .apiHost('http://www.tumblr.com/api')
  .oauthHost('http://www.tumblr.com')
  .entryPath('/auth/tumblr')
  .callbackPath('/auth/tumblr/callback')
  .sendCallbackWithAuthorize(false)
  .fetchOAuthUser( function (accessToken, accessTokenSecret, params) {
    var promise = this.Promise();
    this.oauth.get(this.apiHost() + '/authenticate', accessToken, accessTokenSecret, function (err, data) {
        if (err) return promise.fail(err);
      var parser = new Parser();
      parser.on('end', function (result) {
        var oauthUser;
        if(result.tumblelog instanceof Array){
          oauthUser = result.tumblelog[0]['@'];
        } else {
          oauthUser = result.tumblelog['@'];
        }
        promise.fulfill(oauthUser);
      });
      parser.parseString(data);
    });
    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 new Error(data.data);
  });
{'fraction_non_alphanumeric': 0.1504491017964072, 'fraction_numerical': 0.0014970059880239522, 'mean_word_length': 3.125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5757800', 'n_tokens_mistral': 858, 'n_tokens_neox': 833, 'n_words': 171}