<commit_before>import { defaults } from 'lodash';
import request from 'request';
import config from '../../config';

export default (url, options = {}) => {
  return new Promise((resolve, reject) => {
    const opts = defaults(options, {
      method: 'GET',
      timeout: config.REQUEST_TIMEOUT_MS,
    });

    request(url, opts, (err, response) => {
      if (!!err || response.statusCode !== 200) {
        return reject(err || new Error(response.body));
      }
<commit_msg>Improve error handling by returning the `statusCode` and including the failed URL in the rejected Error<commit_after>import { get, defaults, compact } from 'lodash';
import request from 'request';
import config from '../../config';

export default (url, options = {}) => {
  return new Promise((resolve, reject) => {
    const opts = defaults(options, {
      method: 'GET',
      timeout: config.REQUEST_TIMEOUT_MS,
    });

    request(url, opts, (err, response) => {
      if (!!err || response.statusCode !== 200) {
        if (err) return reject(err);

        const message = compact([
          get(response, 'request.uri.href'),
          response.body,
        ]).join(' - ');
        const error = new Error(message);
        error.statusCode = response.statusCode;
        return reject(error);
      }

{'fraction_non_alphanumeric': 0.14837712519319937, 'fraction_numerical': 0.00463678516228748, 'mean_word_length': 2.9006024096385543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1827751', 'n_tokens_mistral': 367, 'n_tokens_neox': 359, 'n_words': 110}