<commit_before>var ldap = require('ldapjs');

function AuthUser (url, username, password, domainComponent, field, callback) {
    var client = ldap.createClient({
        url: url
    });

    var opts = {
        filter: '(&(' + field + '='+ username + '))',
        scope: 'sub'
    };

    client.search(domainComponent, opts, function(err, search) {
        var users = [];
        if (err) {
            console.log(err);
        }
        search.on('searchEntry', function (entry) {
            if (entry) {
                users.push(entry.dn);
            } 
        });
        search.on('error', function (err) {
            console.log('error: ' + err);<commit_msg>add connect ldap error handler<commit_after>var ldap = require('ldapjs');

function AuthUser (url, username, password, domainComponent, field, callback) {
    var client = ldap.createClient({
        url: url
    });

    var opts = {
        filter: '(&(' + field + '='+ username + '))',
        scope: 'sub'
    };

    client.once('error', function (err) {
        if (err) {
            return callback({message: 'connect to ldap server error', code: 500});
        }
    });

    client.search(domainComponent, opts, function(err, search) {
        var users = [];
        if (err) {
            console.log(err);
        }
        search.on('searchEntry', function (entry) {
            if (entry) {
                users.push(entry.dn);
            } 
        });
        search.on('error', function (err) {
            console.log('error: ' + err);
{'fraction_non_alphanumeric': 0.15469973890339425, 'fraction_numerical': 0.0019582245430809398, 'mean_word_length': 1.887005649717514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6210686', 'n_tokens_mistral': 453, 'n_tokens_neox': 440, 'n_words': 103}