<commit_before>var http = require('http');
var https = require('https');
var server = http.createServer();

var key = "<KEY>";
var secret = "<KEY>";

var authOptions = {
    method: 'POST',
    host: 'api.twitter.com',
    path: '/oauth2/token',
    headers: {
        'Authorization': getAuthHeader(),
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
};

function getAuthHeader() {
    var str = key + ":" + secret;
    var ret = new Buffer(str).toString('base64');
    return 'Basic ' + ret;
}


function handleRequest(req, res) {
    var oauthReq = https.request(authOptions, function(response) {
        response.on('data', function (chunk) {
            res.writeHead(200, {'content-type': 'application/json'});
            res.write(chunk);
            res.end();
        });
    });

    oauthReq.write('grant_type=client_credentials');
    oauthReq.end();
}

server.on('request', handleRequest);
server.listen(8080);<commit_msg>Обработка возможных ошибок от сервера авторизации<commit_after>var http = require('http');
var https = require('https');
var server = http.createServer();

var key = "<KEY>";
var secret = "<KEY>";

var authOptions = {
    method: 'POST',
    host: 'api.twitter.com',
    path: '/oauth2/token',
    headers: {
        'Authorization': getAuthHeader(),
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
};

function getAuthHeader() {
    var str = key + ":" + secret;
    var ret = new Buffer(str).toString('base64');
    return 'Basic ' + ret;
}


function handleRequest(req, res) {
    var oauthReq = https.request(authOptions, function(response) {
        response.on('data', function (chunk) {
            res.writeHead(response.statusCode, {'content-type': 'application/json'});
            res.write(chunk);
            res.end();
        });
    });

    oauthReq.on('error', function(data) {
        res.writeHead(500, {'content-type': 'application/json'});
        var dataObj = {
            errors: [
                {
                    code: 666,
                    label: "Network error",
                    message: "Unable to connect to auth server"
                }
            ]
        };
        res.write(JSON.stringify(dataObj));
        res.end();
    })

    oauthReq.write('grant_type=client_credentials');
    oauthReq.end();
}

server.on('request', handleRequest);
server.listen(8080);
{'fraction_non_alphanumeric': 0.16175860638739112, 'fraction_numerical': 0.010369141435089175, 'mean_word_length': 2.578635014836795, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '426552', 'n_tokens_mistral': 761, 'n_tokens_neox': 738, 'n_words': 148}