<commit_before>'use strict';

/*
 * This module is the interface to the Tenon API.
 * Receives two paramters: options (includes the URL or path to a file) and a callback.
 * Given options and a reference to an html target, it will:
 *   - if the reference is a local file, inline local scripts and css and hand it off to the tenon API
 *   - if the reference is http, hand it off as is to the tenon API
 *
 */

module.exports = function(opts, callback) {
  var Promise = require('bluebird'),
      fs = Promise.promisifyAll(require("fs")),
      merge = require('merge'),
      request = require('request'),
      URL = require('url'),
      inliner = require('./inliner'),
      defaults = {
        fragment: '0',
        ref: '0',
        store: '0',
        viewPortHeight: '768',
        viewPortWidth: '1024',
        urlPrefix: ''
      },
      res,
      fname,
      filter = [],
      cfg
  ;

  function haveResults(err, response, body) {
    var jsn;
    if (err) {
      callback(err);
      return;
    }
    try {
      jsn = JSON.parse(body);
    } catch(e) {<commit_msg>Check response.statusCode is equal to 200 before attempting to parse body JSON<commit_after>'use strict';

/*
 * This module is the interface to the Tenon API.
 * Receives two paramters: options (includes the URL or path to a file) and a callback.
 * Given options and a reference to an html target, it will:
 *   - if the reference is a local file, inline local scripts and css and hand it off to the tenon API
 *   - if the reference is http, hand it off as is to the tenon API
 *
 */

module.exports = function(opts, callback) {
  var Promise = require('bluebird'),
      fs = Promise.promisifyAll(require("fs")),
      merge = require('merge'),
      request = require('request'),
      URL = require('url'),
      inliner = require('./inliner'),
      defaults = {
        fragment: '0',
        ref: '0',
        store: '0',
        viewPortHeight: '768',
        viewPortWidth: '1024',
        urlPrefix: ''
      },
      res,
      fname,
      filter = [],
      cfg
  ;

  function haveResults(err, response, body) {
    var jsn;
    if (err) {
      callback(err);
      return;
    }
    if (response && response.statusCode !== 200) {
      callback('Resp Status: ' + response.statusCode);
      return;
    }
    try {
      jsn = JSON.parse(body);
    } catch(e) {
{'fraction_non_alphanumeric': 0.11998310097169412, 'fraction_numerical': 0.010984368398817067, 'mean_word_length': 2.330520393811533, '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': '6383073', 'n_tokens_mistral': 721, 'n_tokens_neox': 697, 'n_words': 253}