<commit_before>'use strict';

var _ = require('underscore'),
  request = require('request');

var SlackRes = function(config) {
  if (!(this instanceof SlackRes)) {
    return new SlackRes(config);
  }

  this.config = _.defaults(config, {
    mapUpdatedPeriod: 600,
    isAutoUpdated: true
  });

  this.slackUsers = {};
  this.slackChannels = {};
  this.userMap = {};        // id:name
  this.avatarMap = {};      // name:avatar_url
  this.channelMap = {};     // id:name

  this.update();
};

SlackRes.prototype._check = function(body) {
  if (typeof body === 'undefined') {
    throw new Error('Error! Can\'t get resource! Please check the Internet');
  } else if (!JSON.parse(body).ok) {
    throw new Error('Error! Invalid Slack API Token');
  }
};

SlackRes.prototype._updateUsers = function() {
  request.get({
      url: 'https://slack.com/api/users.list?token=' + this.config.token
  }, function(error, response, body) {
    this._check(body);

    var
    res = JSON.parse(body),
    userMap = this.getUserMap(),
    avatarMap = this.getAvatarMap();

    res.members.map(function(member) {
      userMap[member.id] = member.name;
      avatarMap[member.name] = member.profile.image_48;
    });

    this.setUsers(res.members);
    this.setUserMap(userMap);
    this.setAvatarMap(avatarMap);
  }.bind(this));
};

SlackRes.prototype._updateChannels = function() {
  request.get({
      url: 'https://slack.com/api/channels.list?token=' + this.config.token
  }, function(error, response, body) {
    this._check(body);

    var
    channelMap = this.getChannelMap(),
    res = JSON.parse(body);

    res.channels.map(function(channel) {
      channelMap[channel.id] = channel.name;
    });

    this.setChannels(res.channels);
    this.setChannelMap(channelMap);
  }.bind(this));
};<commit_msg>Remove abort of program when catch without resource<commit_after>'use strict';

var _ = require('underscore'),
  request = require('request');

var SlackRes = function(config) {
  if (!(this instanceof SlackRes)) {
    return new SlackRes(config);
  }

  this.config = _.defaults(config, {
    mapUpdatedPeriod: 600,
    isAutoUpdated: true
  });

  this.slackUsers = {};
  this.slackChannels = {};
  this.userMap = {};        // id:name
  this.avatarMap = {};      // name:avatar_url
  this.channelMap = {};     // id:name

  this.update();
};

SlackRes.prototype._check = function(body) {
  if (!JSON.parse(body).ok) {
    throw new Error('Error! Invalid Slack API Token');
  }
};

SlackRes.prototype._updateUsers = function() {
  request.get({
      url: 'https://slack.com/api/users.list?token=' + this.config.token
  }, function(error, response, body) {
    if (!error && response.statusCode == 200) {
      this._check(body);

      var
      res = JSON.parse(body),
      userMap = this.getUserMap(),
      avatarMap = this.getAvatarMap();

      res.members.map(function(member) {
        userMap[member.id] = member.name;
        avatarMap[member.name] = member.profile.image_48;
      });

      this.setUsers(res.members);
      this.setUserMap(userMap);
      this.setAvatarMap(avatarMap);
    } else {
      console.error('Error! Can\'t get resource! Please check the Internet');
    }
  }.bind(this));
};

SlackRes.prototype._updateChannels = function() {
  request.get({
      url: 'https://slack.com/api/channels.list?token=' + this.config.token
  }, function(error, response, body) {
    if (!error && response.statusCode == 200) {
      this._check(body);

      var
      channelMap = this.getChannelMap(),
      res = JSON.parse(body);

      res.channels.map(function(channel) {
        channelMap[channel.id] = channel.name;
      });

      this.setChannels(res.channels);
      this.setChannelMap(channelMap);
    } else {
      console.error('Error! Can\'t get resource! Please check the Internet');
    }
  }.bind(this));
};
{'fraction_non_alphanumeric': 0.15991692627206647, 'fraction_numerical': 0.004153686396677051, 'mean_word_length': 3.0858960763520678, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '2174953', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1243, 'n_words': 226}