<commit_before>"use strict"; 

var winston = require('winston');

var Error404 = function (msg) {
  this.name = 'Error404';
  Error.call( this, msg || 'Page not found' );
  Error.captureStackTrace(this, Error404);
};

Error404.prototype = Error.prototype;


module.exports = {
  Error404: Error404,

  // TODO - move to middleware
  errorHandler: function (err, req, res, next) {
    if(!err) next();

    console.log(err);

    if (err instanceof Error404) {
      res.render('errors/404', {status: 404});
    } else {
      winston.error( err.stack );
      next(err);
    }

  },
};<commit_msg>Fix incorrect error handling<commit_after>"use strict"; 

var winston = require('winston');

var Error404 = function (msg) {
  this.name = 'Error404';
  Error.call( this, msg || 'Page not found' );
  Error.captureStackTrace(this, Error404);
};

Error404.prototype = Error.prototype;


module.exports = {
  Error404: Error404,

  // TODO - move to middleware
  errorHandler: function (err, req, res, next) {
    if(!err) next();

    if (err.name === 'Error404') {
      res.render('errors/404', {status: 404});
    } else {
      winston.error( err.stack );
      next(err);
    }

  },
};
{'fraction_non_alphanumeric': 0.16188870151770657, 'fraction_numerical': 0.045531197301854974, 'mean_word_length': 3.1795774647887325, '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': '6666226', 'n_tokens_mistral': 440, 'n_tokens_neox': 388, 'n_words': 97}