<commit_before>const passport = require('passport');
const Strategy = require('passport-twitter').Strategy;
const express = require('express');
const app = express();
const appSecret = process.env.APP_SECRET || 'oh dear oh dear';
const REDIS = require('redis');
const session = require('express-session');
const RedisStore = require('connect-redis')(session);
const denodeify = require('denodeify');
const extend = require('util')._extend;
const redis = (function () {
	if (process.env.REDISTOGO_URL) {
		const rtg = require('url').parse(process.env.REDISTOGO_URL);
		const redis = REDIS.createClient(rtg.port, rtg.hostname);

		redis.auth(rtg.auth.split(':')[1]);
		return redis;
	} else {
	 	return REDIS.createClient();
	}
}());

const redisGet = denodeify(redis.get).bind(redis);
const redisSet = denodeify(redis.set).bind(redis);

function genIdToProfile(profile) {
	return 'v1.0.1_profile_by_number_' + profile.id;
}

function genUserNameToId(profile) {
	return 'v1.0.0_id_by_username_' + profile.username;
}

function genMessagesForId(profile) {
	return 'v1.0.0_messages_for_' + profile.id;
}

function getSummary(profile) {
	return {
		id: profile.id,
		username: profile.username,
		displayName: profile.displayName,
		photos: profile.photos[0]
	};
}

passport.use(new Strategy(
	{
		consumerKey: process.env.CONSUMER_KEY,
		consumerSecret: process.env.CONSUMER_SECRET,
		callbackURL: global.serverUrl + '/auth/twitter/return'
	},
	function(token, tokenSecret, profile, cb) {

		redisGet(genIdToProfile(profile))
		.then(data => JSON.parse(data))
		.then(inProfile => {
			if (inProfile) {

				// Old User update profile with new Data
				extend(inProfile, profile);
				return inProfile;
			} else {

				//New user
				return profile;
			}
		})
		.then(profile => {

			return Promise.all([
				redisSet(genIdToProfile(profile), JSON.stringify(profile)),

				// Update map of user names to profile ids
				redisSet(genUserNameToId(profile), profile.id)
			]).then(() => profile);
		})
		.then(profile => cb(null, profile));
	}
));

passport.serializeUser(function(user, cb) {
	if (!user.id) {
		return cb('error getting id');<commit_msg>Error handling<commit_after>const passport = require('passport');
const Strategy = require('passport-twitter').Strategy;
const express = require('express');
const app = express();
const appSecret = process.env.APP_SECRET || 'oh dear oh dear';
const REDIS = require('redis');
const session = require('express-session');
const RedisStore = require('connect-redis')(session);
const denodeify = require('denodeify');
const extend = require('util')._extend;
const redis = (function () {
	if (process.env.REDISTOGO_URL) {
		const rtg = require('url').parse(process.env.REDISTOGO_URL);
		const redis = REDIS.createClient(rtg.port, rtg.hostname);

		redis.auth(rtg.auth.split(':')[1]);
		return redis;
	} else {
	 	return REDIS.createClient();
	}
}());

const redisGet = denodeify(redis.get).bind(redis);
const redisSet = denodeify(redis.set).bind(redis);

function genIdToProfile(profile) {
	return 'v1.0.1_profile_by_number_' + profile.id;
}

function genUserNameToId(profile) {
	return 'v1.0.0_id_by_username_' + profile.username;
}

function genMessagesForId(profile) {
	return 'v1.0.0_messages_for_' + profile.id;
}

function getSummary(profile) {
	return {
		id: profile.id,
		username: profile.username,
		displayName: profile.displayName,
		photos: profile.photos[0]
	};
}

passport.use(new Strategy(
	{
		consumerKey: process.env.CONSUMER_KEY,
		consumerSecret: process.env.CONSUMER_SECRET,
		callbackURL: global.serverUrl + '/auth/twitter/return'
	},
	function(token, tokenSecret, profile, cb) {

		redisGet(genIdToProfile(profile))
		.then(data => JSON.parse(data))
		.then(inProfile => {
			if (inProfile) {

				// Old User update profile with new Data
				extend(inProfile, profile);
				return inProfile;
			} else {

				//New user
				return profile;
			}
		})
		.then(profile => {

			return Promise.all([
				redisSet(genIdToProfile(profile), JSON.stringify(profile)),

				// Update map of user names to profile ids
				redisSet(genUserNameToId(profile), profile.id)
			]).then(() => profile);
		})
		.then(profile => cb(null, profile));
	}
));

passport.serializeUser(function(user, cb) {
	if (!user.id) {
		return cb(Error('error getting id'));
{'fraction_non_alphanumeric': 0.15041782729805014, 'fraction_numerical': 0.00510677808727948, 'mean_word_length': 4.640052356020942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7021331', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1471, 'n_words': 294}