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

const requestHelper = (payload, res) => {
  const requestOpts = {
    url: process.env.SLACK_WEBHOOK_URL,
    form: {payload: JSON.stringify(payload)},
  };

  request.post(requestOpts, (err) => {
    if (err) {
      return res.status(500).send({success: false, error: err.message});
    }
    return res.status(200).send();
  });
};

module.exports = requestHelper;<commit_msg>return error when SLACK_WEBHOOK_URL environment variable is not set<commit_after>const request = require('request');

const slackUrl = process.env.SLACK_WEBHOOK_URL;

module.exports = (payload, res) => {
  if (!slackUrl) {
    const noUrlMsg = 'SLACK_WEBHOOK_URL environment variable is not set';
    return res.status(500).send({success: false, error: noUrlMsg});
  }

  const requestOpts = {
    url: slackUrl,
    form: {payload: JSON.stringify(payload)},
  };

  request.post(requestOpts, (err) => {
    if (err) {
      return res.status(500).send({success: false, error: err.message});
    }
    return res.status(200).send();
  });
};
{'fraction_non_alphanumeric': 0.15391791044776118, 'fraction_numerical': 0.013992537313432836, 'mean_word_length': 3.9675925925925926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2059006', 'n_tokens_mistral': 366, 'n_tokens_neox': 349, 'n_words': 76}