<commit_before>/*
* @Author: enzo
* @Date:   2016-11-30 11:08:34
* @Last Modified by:   slashhuang
* @Last Modified time: 2016-12-27 10:38:38
*/

const winston = require('winston');
const path = require('path');

/**
 * 404 or 500错误页面
 */
module.exports = function (){
    return function (ctx, next) {
        return next()
        .then(()=>{
            const status = ctx.status;
            if (status === 404) {
                ctx.throw('404 page',404)
            }
        })
        .catch(err => {
            // 处理400、500等未捕获的错误
            let { status }= err;
            if(status){
                if (status === 404) {
                    global.logger.warn('request Path is ',ctx.url,'404 page redirect => path "/"');
                    ctx.status = 404;
                    ctx.redirect('/');
                }else{
                    global.logger.error(JSON.stringify(err,2,2));
                }
            }else{
                //未知错误
               global.logger.error(err.name + '\n' + err.message);
               ctx.body = err.stack;
               ctx.status = 500;
            };   
        })
    }
}<commit_msg>print error stack to fe<commit_after>/*
* @Author: enzo
* @Date:   2016-11-30 11:08:34
* @Last Modified by:   slashhuang
* @Last Modified time: 2016-12-27 10:38:38
*/

const winston = require('winston');
const path = require('path');

/**
 * 404 or 500错误页面
 */
module.exports = function (){
    return function (ctx, next) {
        return next()
        .then(()=>{
            const status = ctx.status;
            if (status === 404) {
                ctx.throw('404 page',404,dd)
            }
        })
        .catch(err => {
            // 处理400、500等未捕获的错误
            let { status }= err;
            if(status){
                if (status === 404) {
                    global.logger.warn('request Path is ',ctx.url,'404 page redirect => path "/"');
                    ctx.status = 404;
                    ctx.redirect('/');
                }else{
                    global.logger.error(JSON.stringify(err,2,2));
                }
            }else{
                //未知错误
               global.logger.error(err.name + '\n' +err.message+'\n'+ err.stack);
               ctx.body = err.stack;
               ctx.status = 500;
            };   
        })
    }
}
{'fraction_non_alphanumeric': 0.15030146425495264, 'fraction_numerical': 0.05426356589147287, 'mean_word_length': 1.2977250247279921, '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': '7627276', 'n_tokens_mistral': 808, 'n_tokens_neox': 706, 'n_words': 147}