<commit_before>/*
 * catch 404 and forward to error handler
 */
function _404(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
}

/*
 * development error handler
 * will print stacktrace
 */
function dev_500(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error.html', {
        message: err.message,
        error: err
    });
}

/*
 * production error handler
 * no stacktraces leaked to user
 */
function _500(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error.html', {
        message: err.message,
        error: {}
    });
}

module.exports = function(app, config){
    app.use(_404);
    if (app.get('env') === 'development') app.use(dev_500);
    app.use(_500);
};<commit_msg>ROUTES: handle 404 and 500<commit_after>/*
 * catch 404 and forward to error handler
 */
function _404(req, res, next) {
    res.status(404).render('404', {
        url: req.originalUrl,
        error: 'Not found'
    });
}

/*
 * production error handler
 * no stacktraces leaked to user
 */
function _500(err, req, res, next) {
    // treat as 404
    if (err.message
        && (~err.message.indexOf('not found')
        || (~err.message.indexOf('Cast to ObjectId failed')))) {
            return next();
    }

    console.error(err.stack);
    // error page
    res.status(500).render('500', { error: err.stack });
}

module.exports = function(app, config){
    app.use(_500);
    app.use(_404);
};
{'fraction_non_alphanumeric': 0.16352624495289367, 'fraction_numerical': 0.04441453566621804, 'mean_word_length': 2.6898263027295286, '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': '5064342', 'n_tokens_mistral': 541, 'n_tokens_neox': 484, 'n_words': 125}