<commit_before>var request = require('request');

module.exports = function(accessToken) {
    var options = {
        url: 'https://api.github.com/events',
        headers: {
            'User-Agent': 'OGHHR',
            'Authorization': 'token ' + accessToken,
            'If-None-Match': '""',
        }
    };
    var log = {
        ratelimit: {
            limit: 5000,
            remaining: 0,
            reset: 0
        },
        events: 0,
        requests: 0,
    };
    var parseInfo = function(headers, events) {
            options.headers['If-None-Match'] = headers['etag'];
            log.ratelimit.limit = headers['x-ratelimit-limit'];
            log.ratelimit.remaining = headers['x-ratelimit-remaining'];
            log.ratelimit.reset = headers['x-ratelimit-reset'] * 1000;

            log.events += events.length;
    };
    return {
        getEvents : function(callback) {
            log.requests += 1;
            request(options, function(error, response, body) {
                if(error) {
                    console.log(err);
                }
                if(response.statusCode == 304) {
                    callback([]);
                }
                if(response.statusCode === 200) {
                    var events = JSON.parse(body);
                    parseInfo(response.headers, events);
                    callback(events);
                }
            });
        },
        getInfo: function() {
            return log;
        }
    };
};<commit_msg>Fixed issue with error handling<commit_after>var request = require('request');

module.exports = function(accessToken) {
    var options = {
        url: 'https://api.github.com/events',
        headers: {
            'User-Agent': 'OGHHR',
            'Authorization': 'token ' + accessToken,
            'If-None-Match': '""',
        }
    };
    var log = {
        ratelimit: {
            limit: 5000,
            remaining: 0,
            reset: 0
        },
        events: 0,
        requests: 0,
    };
    var parseInfo = function(headers, events) {
            options.headers['If-None-Match'] = headers['etag'];
            log.ratelimit.limit = headers['x-ratelimit-limit'];
            log.ratelimit.remaining = headers['x-ratelimit-remaining'];
            log.ratelimit.reset = headers['x-ratelimit-reset'] * 1000;

            log.events += events.length;
    };
    return {
        getEvents : function(callback) {
            log.requests += 1;
            request(options, function(error, response, body) {
                if(error) {
                    console.error(error);
                }
                if(response.statusCode == 304) {
                    callback([]);
                }
                if(response.statusCode === 200) {
                    var events = JSON.parse(body);
                    parseInfo(response.headers, events);
                    callback(events);
                }
            });
        },
        getInfo: function() {
            return log;
        }
    };
};
{'fraction_non_alphanumeric': 0.13149243918474687, 'fraction_numerical': 0.012491781722550954, 'mean_word_length': 1.3534416086620262, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6901270', 'n_tokens_mistral': 861, 'n_tokens_neox': 802, 'n_words': 144}