<commit_before>'use strict';

// modules > native
const p = require('path');

// modules > 3rd party
const _ = require('lodash');

// modules > internal
const format = require('./util/format-error');
const log = require('./util/log-error');

const config = require(p.join(PWD, 'server/config/error-handler'));

module.exports = function errorHandler(error, req, res, next) {
  error = format(error, req);

  log(error, req, { format: false });

  // limit what properties are sent to the client by overriding toJSON().
  error.toJSON = function () {
    return _.pick(this, config.mystify.properties);
  };

  res.status(error.status).locals = { error };

  next();
};<commit_msg>Only mystify error if membership is activated and user is not admin.<commit_after>'use strict';

// modules > native
const p = require('path');

// modules > 3rd party
const _ = require('lodash');

// modules > internal
const format = require('./util/format-error');
const log = require('./util/log-error');

const config = require(p.join(PWD, 'server/config/error-handler'));

module.exports = function errorHandler(error, req, res, next) {
  error = format(error, req);

  log(error, req, { format: false });

  // limit what properties are sent to the client by overriding toJSON().
  if (req.isAdmin && !req.isAdmin())
    error.toJSON = function () {
      return _.pick(this, config.mystify.properties);
    };

  res.status(error.status).locals = { error };

  if (config.post)
    config.post(req, res, next);
  else
    next();
};
{'fraction_non_alphanumeric': 0.16260697827518103, 'fraction_numerical': 0.0013166556945358788, 'mean_word_length': 3.7648902821316614, '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': '6839077', 'n_tokens_mistral': 475, 'n_tokens_neox': 458, 'n_words': 132}