<commit_before>'use strict';
/**
 * Formats mongoose errors into proper array
 *
 * @param {Array} errors
 * @return {Array}
 * @api public
 */
var errors = function (errors) {
  if (typeof errors === 'string') return [errors];
  if (typeof errors.message === 'string') return [errors.message];

  errors = errors || {};
  const keys = Object.keys(errors);
  const errs = [];

  // if there is no validation error, just display a generic error
  if (!keys) {
    errs.push('Oops! There was an error');
    return errs;
  }

  keys.forEach(key => {
    if (errors[key]) errs.push(errors[key].message);
  });

  return errs;
};
exports.errors = errors;

/**
 * Formats mongoose errors into response for API
 *
 * @param {Array} errors
 * @return {Array}
 * @api public
 */

exports.errsForApi = function (err) {
  return {
    success: false,
    errors: errors(err)
  }
};
<commit_msg>Fixing Error Format in Back End.<commit_after>'use strict';
/**
 * Formats mongoose errors into proper array
 *
 * @param {Array} errors
 * @return {Array}
 * @api public
 */
var errors = function (errors) {
  if (typeof errors === 'string') return [errors];
  if (typeof errors.message === 'string') return [{
      text: errors.message,
      type: 'error'
    }];

  errors = errors || {};
  const keys = Object.keys(errors);
  const errs = [];

  // if there is no validation error, just display a generic error
  if (!keys) {
    errs.push({
      text: 'Oops! There was an error',
      type: 'error'
    });
    return errs;
  }

  keys.forEach(key => {
    if (errors[key]) errs.push({
      text:errors[key].message,
      type: 'error'
    });
  });

  return errs;
};
exports.errors = errors;

/**
 * Formats mongoose errors into response for API
 *
 * @param {Array} errors
 * @return {Array}
 * @api public
 */

exports.errsForApi = function (err) {
  return {
    success: false,
    errors: errors(err)
  }
};

{'fraction_non_alphanumeric': 0.1540073336825563, 'fraction_numerical': 0.0, 'mean_word_length': 3.0041928721174003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3041439', 'n_tokens_mistral': 621, 'n_tokens_neox': 616, 'n_words': 191}