<commit_before>const verifyAccept = require('./verify_accept');
const verifyContentType = require('./verify_content_type');
const verifyDataObject = require('./verify_data_object');

module.exports = function (opts) {
  var sourceInterface = opts.sourceInterface;
  var payload = opts.payload;
  var responder = opts.responder;
  var method = opts.method;
  var source = opts.source;
  var validators = [];

  validators.push(verifyAccept);

  if (method === 'update' || method === 'create') {
    validators.push(verifyContentType);
    validators.push(verifyDataObject);
  }

  return function (request, response, next) {
    var err;

    var endpoint = {
      typeName: opts.typeName,
      id: request.params ? request.params.id : null
    };

    for (var validate in validators) {
      err = validators[validate](request, endpoint);
      if (err) {
        break;
      }
    }

    if (err) {
      return responder(payload(err), request, response);
    }

    sourceInterface(source, opts, request).then(function(data) {
      responder(payload(null, data, opts), request, response, next);
    }).catch(function(err) {
      responder(payload(err), request, response, next);<commit_msg>move content checking to request handler<commit_after>const verifyAccept = require('./verify_accept');
const verifyContentType = require('./verify_content_type');
const verifyDataObject = require('./verify_data_object');

module.exports = function (opts) {
  var sourceInterface = opts.sourceInterface;
  var payload = opts.payload;
  var responder = opts.responder;
  var source = opts.source;
  var validators = [];

  validators.push(verifyAccept);

  return function (request, response, next) {
    var err;

    if (request.body) {
      validators.push(verifyContentType);
      validators.push(verifyDataObject);
    }

    var endpoint = {
      typeName: opts.typeName,
      id: request.params ? request.params.id : null
    };

    for (var validate in validators) {
      err = validators[validate](request, endpoint);
      if (err) {
        break;
      }
    }

    if (err) {
      return responder(payload(err), request, response);
    }

    sourceInterface(source, opts, request).then(function(data) {
      responder(payload(null, data, opts), request, response, next);
    }).catch(function(err) {
      responder(payload(err), request, response, next);
{'fraction_non_alphanumeric': 0.1281078803202697, 'fraction_numerical': 0.0, 'mean_word_length': 3.496212121212121, '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': '6876059', 'n_tokens_mistral': 688, 'n_tokens_neox': 673, 'n_words': 164}